this is the field in griedview
so in .cs how to get its value in GridView1_RowCommand() event?
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

NainilPosted Mar 6, 2010, 4:47 PM
Dipa AhujaPosted Mar 6, 2010, 5:17 AM
i wrote this ways bt i am not getting its value
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
// Get the row index stored in the CommandArgument
int index = Convert.ToInt32(e.CommandArgument);
// Retrieve the row that contains the button clicked
// by the user from the Rows collection.
GridViewRow oRow = GridView1.Rows[index];
// Get the column Text using the Cells collection.
string fid = oRow.Cells[2].Text.ToString();
string myid = oRow.Cells[0].Text.ToString();
}
its working with datalist coz in that its easy like:
string fid = ((Label)e.Item.FindControl("friend_IdLabel")).Text;
string myid = ((Label)e.Item.FindControl("profileIdLabel")).Text;
how to do id this gridview?
NainilPosted Mar 4, 2010, 2:25 PM
To get the column value in the RowCommand event, first you should get the index of the row from the CommandArgument property. Then you can use the index and get the GridViewRow from the GridView.Rows collection. Finally you can query the Cells collection and get the value. Following is the sample code:
// Get the row index stored in the CommandArgument
int index = Convert.ToInt32(e.CommandArgument);
// Retrieve the row that contains the button clicked
// by the user from the Rows collection.
GridViewRow oRow = oGridView.Rows[index];
// Get the column Text using the Cells collection.
string columnValue = oRow.Cells[2].Text;
Hope this helps.