Monday, August 18, 2008

Access another control in a datagrid based on an event from a different control

Say you have a dropdownlist that pops up in a datagrid when you click on the edit link and launch the edit command. And say there is another control in that row that you need a handle to when you change the index of that dropdownlist. Here is how you do it.

I have noticed that it's okay to use Cells(0) regardless of where the column is located.
As long as its in the same row.

Protected Sub drd1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

Dim drd1 As New DropDownList drd1= CType(sender, DropDownList)
Dim drd2 As New DropDownList drd2 = CType(DataGrid1.Items.Item(DataGrid1.EditItemIndex).Cells(0).FindControl("drd2"), DropDownList)



End Sub

No comments: