如何用可单击的方式替换gridview的行命令事件

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

本文关键字:命令 事件 gridview 方式 何用可 单击 替换      更新时间:2023-09-26

我有一个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);
            }
       }

添加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

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

如何实现在GridView全行选择没有选择按钮?

使整个行在gridview中可点击

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