我有一個RowDataBound
事件處理程序看起來像這樣:的RowDataBound DropDownList的
Public Sub CustomersGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GVHistoricNames.RowDataBound 'RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim hyperlinkUSNHyperlink As HyperLink = CType(e.Row.FindControl("USNHyperlink"), HyperLink)
Dim ddl As DropDownList = CType(e.Row.FindControl("ddlUsercode"), DropDownList)
If ddl.SelectedValue = "" Then 'labLastUserCode.Text = "" Then
hyperlinkUSNHyperlink.NavigateUrl = ""
End If
End If
End Sub
...和RowCreated
事件處理程序看起來像這樣:
Public Sub CustomersGridView_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GVHistoricNames.RowCreated 'RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim ddl As DropDownList = CType(e.Row.FindControl("ddlUsercode"), DropDownList)
ddl.Items.Add("")
ddl.Items.Add(strUserName)
End If
End Sub
...和RowUpdating
事件看起來像這樣的處理器:
Protected Sub GVHistoricNames_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GVClearcoreHistoricNames.RowUpdating
Try
Dim ddl As DropDownList = CType(GVHistoricNames.Rows(e.RowIndex).FindControl("ddlUsercode"), DropDownList)
SQLHistoricNames.UpdateParameters("UserCode").DefaultValue = ddl.SelectedValue
Catch ex As Exception
Finally
End Try
End Sub
請看第3行RowUpdating
事件處理程序。因爲RowDataBound
事件處理程序的RowUpdating
事件處理程序後調用的SelectedValue
屬性的值是永遠正確的。我如何訪問SelectedValue
?我想將其設置爲更新參數。
什麼是ddl.UIniqueID? GridView中的每一行都有一個下拉列表。 – w0051977
非常感謝。這已經成功了。我希望我可以多次讚揚這個答案!你能解釋爲什麼上面的行爲不會發生,如果我聲明ASPX文件中的下拉列表項而不是後面的代碼? – w0051977
@ w0051977,請在答案中查看我的編輯內容以瞭解您的疑惑!順便說一句,而不是兩次投票,你可以通過點擊投票箭頭下面的勾號來標記答案。 – VinayC