0

I have a grid view ,i use the row command to open a specific window with several parameters.

Now i want to remove this button and make the whole row clickable so if i click on the row open the same window .How to do that .

 protected void gv_Details1_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            if (e.CommandName == "Confirm")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                Session["task_code"] = ((HiddenField)gv_Details1.Rows[index].Cells[0].FindControl("hf_tc")).Value;
                Session["trans_serial"] = ((HiddenField)gv_Details1.Rows[index].Cells[0].FindControl("hf_ts")).Value;


                MasterPage2 obj = (MasterPage2)Page.Master;
                obj.SetMainVariables();
                obj.PreValidate();
                obj.SetDepartment();

                Response.Redirect("~/Contents/" + Session["page_new"].ToString() + ".aspx", false);

            }
       }
Anyname Donotcare
  • 11,113
  • 66
  • 219
  • 392

3 Answers3

2

Add RowDatabound event :

protected void gv_Details1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("style", "cursor:pointer;");
            string abc = ((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString();
            e.Row.Attributes["onClick"] = "location.href='pagename.aspx?Rumid=" + abc + "'";
        }
    }

Thanks :

Curtsy : http://forums.asp.net/t/1859787.aspx/1?How+to+fire+RowCommand+event+when+user+click+anywhere+in+the+gridview+row

Dev
  • 6,570
  • 10
  • 66
  • 112
1

two of the best links of our own stack overflow community.

How to implement full row selecting in GridView without select button?

Making an entire row clickable in a gridview

Community
  • 1
  • 1
ankur
  • 4,565
  • 14
  • 64
  • 100
1
protected void Grid_RowDataBound(object sender, GridViewRowEventArgs e)
{

    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Product p = (e.Row.DataItem as Product);

        e.Row.Attributes.Add("onClick",  "location.href='somepage.aspx?id=" + p.ProductID + "'");
    }

}
codingbiz
  • 26,179
  • 8
  • 59
  • 96