我有一个 GridView
,我使用行命令
打开带有多个参数的特定窗口。
现在我想删除此按钮并使整行可点击
,这样如果我点击该行,就会打开同一个窗口。如何做到这一点。
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 + "'";
}
}
谢谢:
关于c# - 如何以可点击的方式替换gridview的行命令事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14038707/