I am creating a dropdown list in code for a gridview. I want to create an addhandler so I can have access to the selectedvalue. However, here (Rowdatabound) the add handler does not get fired off. How should I go about this?
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
''//------------does not fire off add handler-----
Dim deptvalue As String
Dim ddlmgr As New DropDownList
AddHandler ddlmgr.SelectedIndexChanged, AddressOf ddlmgr_SelectedIndexChanged
ddlmgr.AutoPostBack = True
ddlmgr.Items.Clear()
ddlmgr.Items.Insert(0, "--Select a Manager--")
ddlmgr.AppendDataBoundItems = True
ddlmgr.DataTextField = "Name"
ddlmgr.DataValueField = "number"
ddlmgr.DataSource = SqlDataSource2
ddlmgr.DataBind()
''//deptvalue = GridView1.Rows(i).Cells(0).Text
deptvalue = e.Row.Cells(0).Text
ddlmgr.Attributes.Add("onchange", "setDepart('" & deptvalue & "')")
If e.Row.RowType <> DataControlRowType.Pager And e.Row.RowType <> DataControlRowType.Header And e.Row.RowType <> DataControlRowType.Footer Then
e.Row.Cells(2).Controls.Add(ddlmgr)
End If
End Sub