2013-08-20 124 views
0

我有一個帶有編輯/更新命令按鈕的gridview。我正在使用下拉菜單爲gridview數據源(ds2)設置selectcommand,如下所示。Gridview更新後沒有綁定

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控件本身更新後綁定

+1

發佈編輯/更新命令的代碼。 –

+0

您是否嘗試在'row_command'事件處理程序結束時重新綁定? –

回答

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