Asp.net 单击以选择gridview中导致在编辑模式下回发的行
当前,当用户单击行上的任意位置时,它会选择该行。不幸的是,在编辑模式下(单击“编辑”后),每当用户单击表单上的任何位置时,表单都会进行回发。如何禁用此功能并允许用户和平地编辑行 这就是我所拥有的允许单击选择行的功能:Asp.net 单击以选择gridview中导致在编辑模式下回发的行,asp.net,select,gridview,onclick,edit,Asp.net,Select,Gridview,Onclick,Edit,当前,当用户单击行上的任意位置时,它会选择该行。不幸的是,在编辑模式下(单击“编辑”后),每当用户单击表单上的任何位置时,表单都会进行回发。如何禁用此功能并允许用户和平地编辑行 这就是我所拥有的允许单击选择行的功能: protected void GridView1_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) { if (e.Row.RowType == DataC
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";
}
}
protectedvoid GridView1\u行已创建(对象发送方,System.Web.UI.WebControls.GridViewRowEventArgs e)
{
如果(e.Row.RowType==DataControlRowType.DataRow)
{
列表不可点击=新建列表();
{
不可点击。添加(0);
}
for(int i=0;i
解决此问题的修订代码:
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";
}
}
}
protectedvoid GridView1\u行已创建(对象发送方,System.Web.UI.WebControls.GridViewRowEventArgs e)
{
如果(e.Row.RowType==DataControlRowType.DataRow)
{
如果(GridView1.EditIndex!=-1)
{
e、 Row.Attributes.Remove(“onmouseover”);
}
其他的
{
列表不可点击=新建列表();
{
不可点击。添加(0);
}
for(int i=0;i
在你的选择函数上,让它删除onclick属性。然后当你完成编辑后,再将其添加回去。谢谢,劳伦斯。我做了一些类似于你建议的事情。请参阅编辑。我知道这很旧,但我只是想感谢修改后的代码/答案!我不知道解决我的问题有多简单(和你的非常相似)直到我看到这个。