在RowDatabound事件中为网格中的每个下拉控件添加javascript验证



我在GridView中使用模板字段。模板字段是在RowDataBound事件中动态生成的下拉列表。

我如何添加一个Javascript验证到每个这些下拉列表时,他们被创建?

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
    Dim gvItem As GridViewRow = e.Row
    If gvItem.RowType = DataControlRowType.DataRow Then
        Dim DropDownList1 As DropDownList = gvItem.FindControl("DropDownList1")
        DropDownList1.Attributes("onchange") = "yourJavascriptValidationFunction(this);"
    End If
End Sub

您可以使用DropDownList.Attributes。添加("onChange"、"yourjavascriptfunction");

最新更新