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
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