0

我的 Web 应用程序中有一个页面,其中包含两个带有按钮的列表框,用于在它们之间来回移动项目。每个列表框都绑定到一个 SQL 查询,其结果会随着所选项目的添加或从相应列表中删除而改变。这一切都很好,除了我无法让列表框即时更新其内容,但是如果我刷新网页,内容会正确更新。

基本上,用户在 LeftListbox 中选择项目并单击 Add 按钮,该按钮调用代码以循环遍历 LeftListbox,并为每个选定的项目添加一个新记录到表(分数)。然后 RightListbox 应更新以显示项目已添加到表中。

下面是来自 Add 按钮的 Click 事件的代码片段:

Dim i As Integer

For i = 0 To (LeftListbox.Items.Count() - 1)

    If LeftListbox.Items(i).Selected Then

        Try
            DbUtils.StartTransaction()

            Dim rec As ScoreRecord = New ScoreRecord
            rec.Player_ID = CInt(Me.LeftListbox.Items(i).Value)
            rec.Save()

            DbUtils.CommitTransaction()

        Catch ex As Exception
            DbUtils.RollBackTransaction()
            Me.Page.ErrorOnPage = True

        Finally
            DbUtils.EndTransaction()

        End Try
    End If

Next i

'** Here is where I want to refresh the list **

我已经搜索了很多解决方案,但我找不到任何有效的方法,因此非常感谢任何帮助。

安德鲁

4

1 回答 1

0

首先使用用于填充“右列表框”的相同方法(或代码)。正确的 ListBox 的 DataSource 将与运行此代码截断之前的相同,因此必须更新它,因为基础数据已更改。

于 2013-06-26T00:18:10.133 回答