0

我有一个带有编辑/更新命令按钮的网格视图。我正在使用下拉菜单来设置 gridview 数据源 (ds2) 的选择命令,如下所示。

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
 If ddFilter.SelectedValue = "Title" Then ds2.SelectCommand = "SELECT * FROM [contentStore] WHERE ([Title] LIKE '%' + @Title + '%') order by [Title] asc"
 If ddFilter.SelectedValue = "URL" Then ds2.SelectCommand = "SELECT * FROM [contentStore] WHERE ([URL] LIKE '%' + @Title + '%') order by [URL] asc"
 If ddFilter.SelectedValue = "ID" Then ds2.SelectCommand = "SELECT * FROM [contentStore] WHERE ([ID] LIKE '%' + @Title + '%') order by [ID] asc"
 GridView1.DataBind()
Catch ex As Exception
 lblFilter.Text = "<h3>Filter Issue</h3>" & ex.ToString
 End Try
End Sub

问题是当我使用编辑/更新组合时,记录会正确更新,但是 gridview 不会再次绑定自身。如果我再次按下按钮,gridview 会按预期重新显示更新的数据。

我的问题是如何让 Gridview 在更新后自行绑定

4

1 回答 1

1

好吧,没有看到您的代码,我的猜测是您需要在命令逻辑中复制按钮单击处理程序中的逻辑,以便执行和绑定网格的 SQL 再次发生,如下所示:

Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
    If e.CommandName = "Edit" Then
        ' Do logic here

        If ddFilter.SelectedValue = "Title" Then 
            ds2.SelectCommand = "SELECT * FROM [contentStore] WHERE ([Title] LIKE '%' + @Title + '%') order by [Title] asc"
        End If

        If ddFilter.SelectedValue = "URL" Then 
            ds2.SelectCommand = "SELECT * FROM [contentStore] WHERE ([URL] LIKE '%' + @Title + '%') order by [URL] asc"
        End If

        If ddFilter.SelectedValue = "ID" Then 
            ds2.SelectCommand = "SELECT * FROM [contentStore] WHERE ([ID] LIKE '%' + @Title + '%') order by [ID] asc"
        End If

        GridView1.DataBind()
    End If
End Sub
于 2013-08-20T18:51:07.493 回答