gpt4 book ai didi

c# - GridView 中的可点击行并编辑该行

转载 作者:行者123 更新时间:2023-11-30 13:04:57 25 4
gpt4 key购买 nike

我在这里遇到关于可编辑 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;");

}

}

最佳答案

只需将控件添加到 Default.aspx 并在 default.aspx 页面加载事件(在非回发条件下)通过 ID 检索记录并填充控件。

现在当按下提交按钮时更新记录并重定向回您的原始页面

关于c# - GridView 中的可点击行并编辑该行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6772170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com