Search code examples
c#javascriptasp.netgridviewrowcommand

How to replace the row command event for a gridview with clickable manner?


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);

            }
       }

Solution

  • 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