GridView中可点击的行,并编辑该行
本文关键字:编辑 GridView | 更新日期: 2023-09-27 18:03:03
我在这里有一个关于可编辑gridview的问题。我想做的是通过使用单个可点击的行来替换编辑按钮功能。当我单击一行时,它应该将我转发到一个新页面以编辑这些行数据。我怎么能做到这一点,不使用编辑按钮?
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
// only apply changes if its DataRow
if (e.Row.RowType == DataControlRowType.DataRow)
{
// when mouse is over the row, save original color to new attribute, and change it to highlight yellow color
e.Row.Attributes.Add("onmouseover",
"this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#EEFF00'");
// when mouse leaves the row, change the bg color to its original value
e.Row.Attributes.Add("onmouseout",
"this.style.backgroundColor=this.originalstyle;");
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string abc = ((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString();
e.Row.Attributes["onClick"] = "location.href='Default.aspx?id=" + abc + "'";
//e.Row.Attributes["onClick"] = "location.href='Default.aspx?id=" + DataBinder.Eval(e.Row.DataItem, "CategoryID") + "'";
e.Row.Attributes.Add("style", "cursor:pointer;");
}
}
只需添加您想要的默认控件。默认为Aspx。aspx页面加载事件(在非回发状态下)通过ID检索记录并填充控件。
现在当提交按钮按下更新记录并重定向到原始页面