0

我有一个grid view,我用row command来打开一个带有几个参数的特定窗口。

现在我想删除这个按钮并使整行clickable,所以如果我点击该行打开同一个窗口。如何做到这一点。

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

            }
       }
4

3 回答 3

2

添加 RowDatabound 事件:

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

谢谢 :

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

于 2012-12-26T09:54:12.910 回答
1

我们自己的堆栈溢出社区的两个最佳链接。

如何在没有选择按钮的情况下在 GridView 中实现全行选择?

在gridview中使整行可点击

于 2012-12-26T09:55:53.207 回答
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 + "'");
    }

}
于 2012-12-26T10:05:41.570 回答