我有一个带有编辑/更新命令按钮的gridview。我正在使用下拉菜单为gridview数据源(ds2)设置select命令,如下所示。
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自行绑定答案 0 :(得分: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