Domanda

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

            }
       }
È stato utile?

Soluzione

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

Altri suggerimenti

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 + "'");
    }

}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top