I have a Gridview in my webpage and there are two button fields included in gridview for selection. One is for "Adding" and other one is for "Editing".
How can i track which button is clicked inside GridView1_SelectedIndexChanged Event? Simply what i want is to get the cell id or the button id of the button clicked. Can anybody give me a hand to sort this out ?
****this is my gridview columns*****
*******this is my Event***********
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
//code goes here
}
Thanks,
Max
MuthuMari MPosted Apr 5, 2012, 2:58 AM
The RowCommand event is raised when a button is clicked in the GridView control
pls refer this url,
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx
Thanks.
If this post is useful then mark it as "Accepted Answer"
CHAITANYA KIRAN KASANIPosted Jan 8, 2013, 6:30 AM
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{ if (e.CommandName == "AddToCart")
{
// Retrieve the row index stored in the
// CommandArgument property.
int index = Convert.ToInt32(e.CommandArgument);
// Retrieve the row that contains the button
// from the Rows collection.
GridViewRow row = GridView1.Rows[index];
// Add code here to add the item to the shopping cart.
double Price = double.Parse(((Label)row.Controls[0].FindControl("PriceLabel")).Text);
string ProductName = ((Label)row.Controls[0].FindControl("NameLabel")).Text;
int ProductID = int.Parse(Request.QueryString["ProductID"]);
if (Profile.SCart == null)
{
Profile.SCart = new ShoppingCart.Cart();
}
Profile.SCart.Insert(ProductID, Price, 1, ProductName);
}
}
Charith LiyanagamagePosted Apr 5, 2012, 3:49 AM
SenthilkumarPosted Apr 5, 2012, 3:14 AM
you need to add the command name to the control. So that when it is clicked you can identify in the item command.
Identify in the row command event of the grid control.