Hi
I have a list of buttons inside my gridview cells, now i need each button to execute a difrent event when its clicked. how can i solve this?
I tried to put this on Page_Load but not working
foreach (GridViewRow rowItem in GridView1.Rows)
{
Button btnMonday = (Button)(GridView1.Rows[0].Cells[1].FindControl("btnMonday"));
btnMonday.Click += new EventHandler(this.mondae_Click);
Button btnTuesday = (Button)(GridView1.Rows[0].Cells[2].FindControl("btnMonday"));
btnTuesday .Click += new EventHandler(this.mondae_Click);
}
What should i do or where should i put it??
Loading

Prabhu RajaPosted Oct 15, 2011, 12:53 AM
i attached my source code with this. Instead of Command button, i have used link button. In code-behind, use link button Event handler , to do the task that you want.
In that code, I retrieved grid row index based on link button click. so, based on row index, you can perform difference tasks.
Javeed M ShaikhPosted Oct 14, 2011, 3:49 PM
you have use the Rowcommand event of the grid like this:
protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if (e.CommandName == "btnMonday")
{
// 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
}
}
Please do not forget to mark "Accepted Answer".