Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > dataitem in SelectedIndexChanged not recognized

Reply
Thread Tools

dataitem in SelectedIndexChanged not recognized

 
 
aamirghanchi@gmail.com
Guest
Posts: n/a
 
      03-09-2007
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
 
 
 
 
aamirghanchi@gmail.com
Guest
Posts: n/a
 
      03-09-2007
On Mar 9, 11:01 am, (E-Mail Removed) wrote:
> 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

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieving the DataItem property in DataList's ItemCommand or SelectedIndexChanged event Nathan Sokalski ASP .Net Building Controls 1 09-13-2007 04:45 PM
Retrieving the DataItem property in DataList's ItemCommand or SelectedIndexChanged event Nathan Sokalski ASP .Net Web Controls 1 09-13-2007 04:45 PM
Retrieving the DataItem property in DataList's ItemCommand or SelectedIndexChanged event Nathan Sokalski ASP .Net 1 09-13-2007 04:45 PM
BC30456: 'DataItem' is not a member of 'System.Web.UI.Control' djc ASP .Net 1 11-22-2004 04:06 PM
Compiler Error BC30456: 'DataItem' is not a member of 'System.Web.UI.Control' ? Zenobia ASP .Net 1 07-06-2004 05:49 PM



Advertisments