gpt4 book ai didi

asp.net - 单击以在 gridview 中选择行导致在编辑模式下回发

转载 作者:行者123 更新时间:2023-12-04 05:30:04 24 4
gpt4 key购买 nike

目前,当用户点击一行上的任何地方时,它会选择该行。不幸的是,在编辑模式下(单击“编辑”后),每次用户单击表单上的任何位置时,表单都会进行回发。如何禁用此功能并让用户安心地编辑该行?

这就是我所拥有的,可以单击以选择行:

protected void GridView1_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
List<int> notClickable = new List<int>();
{
notClickable.Add(0);
}

for (int i = 0; i < e.Row.Cells.Count; i++)
{
if (!notClickable.Contains(i))
{
e.Row.Cells[i].Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);
e.Row.Cells[i].Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);
}
}

e.Row.Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#ceedfc'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalstyle");
e.Row.Attributes.Add("style", "cursor:pointer;");
e.Row.ToolTip = "Click to select row";
}
}

修改了解决问题的代码:
protected void GridView1_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (GridView1.EditIndex != -1)
{
e.Row.Attributes.Remove("onmouseover");
}
else
{
List<int> notClickable = new List<int>();
{
notClickable.Add(0);
}

for (int i = 0; i < e.Row.Cells.Count; i++)
{
if (!notClickable.Contains(i))
{
e.Row.Cells[i].Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);
e.Row.Cells[i].Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);
}
}

e.Row.Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#ceedfc'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalstyle");
e.Row.Attributes.Add("style", "cursor:pointer;");
e.Row.ToolTip = "Click to select row";
}
}
}

最佳答案

在您的选择功能上,删除 onclick 属性。然后当您完成编辑后,将其添加回来。

关于asp.net - 单击以在 gridview 中选择行导致在编辑模式下回发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12753318/

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