I've gotten this to work for one DataGrid DropDownList, but can't figure out how to get it working when there are two DataGrid DropDownLists in an edit row. Here is my code, which I got from a post linking to MSDN:
I have two DropdownLists in the edit row and I can't figure out how to get the second one (ddlFacilityType) to retain the current selected text when the edit command is issued. Is my approach in the above code wrong?
Thanks, Joe
Code:
Private Sub FacilityGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles FacilityGrid.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim currentcustname As String = CType(drv("cust_name"), String)
Dim ddl As DropDownList
ddl = CType(e.Item.FindControl("ddlCustomerName"), DropDownList)
ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByText(currentcustname))
Dim currentfactype As String = CType(drv("facilitytype_desc"), String)
Dim ddl1 As DropDownList
ddl1 = CType(e.Item.FindControl("ddlFacilityType"), DropDownList)
ddl1.SelectedIndex = ddl1.Items.IndexOf(ddl1.Items.FindByText(currentfactype))
End If
End Sub
I have two DropdownLists in the edit row and I can't figure out how to get the second one (ddlFacilityType) to retain the current selected text when the edit command is issued. Is my approach in the above code wrong?
Thanks, Joe