![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I have scoured this user group for this answer to no avail. I am trying to get the Datatitem property of the DataGridItem in the SelectedIndexChanged event handler of a Dropdownlist in a Templatecolumn of a DataGrid (mouthfull huh!). Due to client requirements, I am not doing it through EditColumn way. User does not want to go through clicking Edit and Update buttons for selection change. Therefore the DropdownList is in the ItemTemplate of Templatecolumn. The DataGrid is being bind in the Page_Load event dynamically to a datasource. In the SelectedIndexChanged handler I am trying to get the Primary key column value in the DataItem so that it can be used to update the database table row. I am able to get to the DataGridItem though, but further than that it blows up on me when I try to get the DataItem out of DataGridItem with NullReferenceException: just to keep it simple I am casting the DataItem into DataRowView and trying to get the GetType() from it. Here is the code snippet: Public Sub ddlMyDropDownList_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Dim ddl As DropDownList = CType(sender, DropDownList) Dim dgi As DataGridItem = CType(ddl.NamingContainer, DataGridItem) Dim strObjType As String = CType(dgi.DataItem, DataRowView).GetType().ToString() End Sub It raises NullReferenceException on he last line before End Sub "Object reference not set to an instance of an object. System.NullReferenceException" Does anyone know of a reason why it won't recognize the DataItem object of the DataGridItem in SelectedIndexchanged event? Will appreciate any leads. Thanks (Doing it in .Net 1.1 and VB grudgingly on a legacy web app) |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |