get gridview column value in rowcommand event in c#

Posted by Sekar.C under C# on 3/19/2012 | Points: 10 | Views : 30994 | Status : [Member] | Replies : 4
hi,
how to get gridview column value in rowcommand event in c#
regrads
sekar.c

Regards
Sekar.c



Responses

Posted by: Sabarimahesh on: 3/20/2012 [Member] Bronze | Points: 25

Up
0
Down
GridViewRow GVRow = (GridViewRow)(((Repeater)e.CommandSource).NamingContainer); 

Repeater Rep= GVRow .Cells[8].FindControl("RepReg") as Repeater;



GridViewRow GVRow = Grd.SelectedRow;
Repeater Rep1= Grd.Rows[e.RowIndex].Cells[8].FindControl("RepReg") as Repeater;
Repeater Rep2= Grd.Rows[e.RowIndex].Cells[9].FindControl("RepVisitor") as Repeater;
foreach (RepeaterItem RI in Rep1.Items)
{
TextBox Txt1= item.FindControl("Txt_Id") as TextBox;
TextBox Txt2= item.FindControl("Txt_Name") as TextBox;
//update db
}


Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 3/20/2012 [Member] Bronze | Points: 25

Up
0
Down
You can get gridview column value in RowDataBound even by following code.

TextBox txtName = (TextBox)e.Row.FindControl("txtName"); //if you have any template column and that have the textbox named txtName

RowCommand event of a gridview is fired when any button is clicked in the gridview
And in rowCommand event, you can get the command name by using e.CommandName and to get the column value use the following code....

int iIndex=Convert.ToInt32(e.CommandArgument);
GridViewRow gvRow= GV.Rows[iIndex];
string strGVValue=server.HtmlDecode(gvRow.Cells[1].Text);


For more information you can refer http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx

Thanks,
Rajni Shekhar

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 3/20/2012 [Member] Bronze | Points: 25

Up
0
Down
Rajni.Shekhar
i feel its easy

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijetha on: 3/20/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
You can follow this also.

protected void grd4_RowCommand(object sender, GridViewCommandEventArgs e)
{
int i = Convert.ToInt32(e.CommandArgument);
if (e.CommandName == "select")
{

var Price = ((Label)grd4.Rows[index].Cells[3].FindControl("lblRPrice")).Text.Trim(); //If its label
OR
var Price = ((TextBox)grd5.Rows[i].Cells[6].FindControl("txtPrice")).Text.Trim(); //if its textbox


}
}


Regards,
Vijetha.M.M

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response