Peril
Peril

Reputation: 1599

Using Multiple "Select" inside the GridView

What I am trying to do is have a grid view with 3 "select" and I renamed them to edit , delete and details

and each one should redirect to a certain page

my question , how I can know which column or "Select" the user clicked

Thanks

Upvotes: 2

Views: 3277

Answers (2)

shamcs
shamcs

Reputation: 629

string commandName = e.CommandName.ToString().Trim();
  GridViewRow row = GridView1.Rows[Convert.ToInt32(e.CommandArgument)];
  switch (commandName)
  {
      case "showName":                   
          LClickName.Text = "You Clicked Show Name Button : \"" + row.Cells[1].Text + "\"";                   
          break;
      case "EditName":                   
          LClickName.Text = "You Clicked Edit Name Button : \"" + row.Cells[1].Text + "\"";                  
          break;
      default: break;
  }

Here is a sample for Multiple select Button in One Gridview

Multiple Select Button In One Gridview

Upvotes: 0

Anders Abel
Anders Abel

Reputation: 69270

Set the CommandName property of your buttons. Then add an event handler for the RowCommand event of the gridview:

protected void MyGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
  switch(e.CommandName)
  {
    case "SomeCommand":
      Response.Redirect("SomePage.aspx");
      break;
    case "OtherCommand":
      Respone.Redirect("OtherPage.aspx");
}

Upvotes: 1

Related Questions