I have a gridview with a dropdown list that was created programmatcially. I want to have
access to the selected value and to that row's Id. I have the dropdownlist created in *Gridview_RowDataBound* and I am able to use the text in the cell but my addHandler is never fired. Where do I give it the Add handler. I believe I can assign it the addhandler in RowCreated but how would I be able to set up the add handler if the button is created in rowdatabound?
Dim deptvalue As String
Dim i As Integer = 0
Dim ddlmgr As New DropDownList
ddlmgr.AutoPostBack = True
AddHandler ddlmgr.SelectedIndexChanged, AddressOf ddlmgr_SelectedIndexChanged
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 = 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
If e.Row.RowType <> DataControlRowType.Pager And e.Row.RowType <> DataControlRowType.Footer Then
e.Row.Cells(0).Style.Add("display", "none")
End If
It fits best in Rowdata bound because my dropdownlist items don't duplicate but I need to be able to use the addhandler I created.