this is the field in griedview
so in .cs how to get its value in GridView1_RowCommand() event?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Nainil148 reputationPosted Mar 4, 2010, 9:25 AM EST
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.
Dipa AhujaRank #1,168 · 1.5K reputationPosted Mar 6, 2010, 12:17 AM EST
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?
Nainil148 reputationPosted Mar 6, 2010, 11:47 AM EST