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

Joined
Feb 11, 2008
Messages
1
Reaction score
0
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top