HighTechTalks DotNet Forums  

dataitem in SelectedIndexChanged not recognized

ASP.net Data Grid Control microsoft.public.dotnet.framework.aspnet.datagridcontrol


Discuss dataitem in SelectedIndexChanged not recognized in the ASP.net Data Grid Control forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
aamirghanchi@gmail.com
 
Posts: n/a

Default dataitem in SelectedIndexChanged not recognized - 03-09-2007 , 12:01 PM






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)


Reply With Quote
  #2  
Old   
aamirghanchi@gmail.com
 
Posts: n/a

Default Re: dataitem in SelectedIndexChanged not recognized - 03-09-2007 , 05:38 PM






On Mar 9, 11:01 am, aamirghan... (AT) gmail (DOT) com wrote:
Quote:
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)
answering my own post.
I guess the DataItem object is no more available right after the
ItemDataBound event of DataGrid as it says in the documentation
ms-help://MS.MSDNQTR.2003FEB.1033/cpref/html/
frlrfSystemWebUIWebControlsDataGridClassItemDataBo undTopic.htm

"After this event is raised, the data item is nulled out and no longer
available."



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.