Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Retrieve the data from the GridViewRow by column name instead of index

Thread Tools

Retrieve the data from the GridViewRow by column name instead of index

agora1983 agora1983 is offline
Junior Member
Join Date: Feb 2008
Posts: 1
Hi there, everyone.
I want to retrieve the data from the GridViewRow by column name instead of index.
But the error prompt as "Cannot apply indexing with [] to an expression of type 'object ".
How should I resolve it?
Or I have to use something else instead of GridViewRow?

protected void CustomersGridView_RowCommand(Object sender, GridViewCommandEventArgs e) {
// If multiple ButtonField column fields are used, use the
// CommandName property to determine which button was clicked.
if( e.CommandName == "Select" ) {

// Convert the row index stored in the CommandArgument
// property to an Integer.
int index = Convert.ToInt32( e.CommandArgument );

// Get the project id from the appropriate
// cell in the GridView control.
GridViewRow selectedRow = GridView1.Rows[ index ];
//The following line doesn't work
Session[ "ProjectID" ] = selectedRow.DataItem[ "ProjectID" ];

// These two lines work
Session[ "ClientName" ] = selectedRow.Cells[ 2 ].Text;
Session[ "ProjectName" ] = selectedRow.Cells[ 3 ].Text;


Thanks in advance.

-- Joe
Reply With Quote

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
sorting index-15, index-9, index-110 "the human way"? Tomasz Chmielewski Perl Misc 4 03-04-2008 05:01 PM
foreach GridViewRow not seeing first row in dataset. walterb ASP .Net 0 09-13-2007 01:37 PM
how can i retrieve the name of form when one of the element name in this form is 'name' Javascript 6 11-24-2006 02:54 AM
added GridViewRow Dynamically with textbox but missing viewstate silverfox_1188 ASP .Net 0 07-25-2006 07:59 PM
use column name instead of index msnews ASP .Net 2 09-28-2005 10:38 AM