大家好。今天碰到一个稍微奇怪点的问题。
在用GridView的时候,我在rowdatabound里写下下面的代码
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#66ccff'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
((LinkButton)(e.Row.Cells[5].Controls[0])).Attributes.Add("onclick", "return confirm('确认删除?');");
}
}删除按钮的索引是5,这个我确认过,删除按钮是可以用的。
在rowediting里写了如下代码protected void GridView_RowEditing(object sender, GridViewEditEventArgs e)
{
this.GridView.EditIndex = e.NewEditIndex;
this.GridViewBinding();
}这时候调试,发现上述
((LinkButton)(e.Row.Cells[5].Controls[0])).Attributes.Add("onclick", "return confirm('确认删除?');");
报错
如果将其注释掉,运行正常。
但是,这句子本身应该是没有错的。它只是为删除按钮添加弹出确认窗口的功能而已。
报错的内容是:指定的参数已超出有效值的范围。参数名:INDEX疑惑不解,请高手赐教。
在用GridView的时候,我在rowdatabound里写下下面的代码
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#66ccff'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
((LinkButton)(e.Row.Cells[5].Controls[0])).Attributes.Add("onclick", "return confirm('确认删除?');");
}
}删除按钮的索引是5,这个我确认过,删除按钮是可以用的。
在rowediting里写了如下代码protected void GridView_RowEditing(object sender, GridViewEditEventArgs e)
{
this.GridView.EditIndex = e.NewEditIndex;
this.GridViewBinding();
}这时候调试,发现上述
((LinkButton)(e.Row.Cells[5].Controls[0])).Attributes.Add("onclick", "return confirm('确认删除?');");
报错
如果将其注释掉,运行正常。
但是,这句子本身应该是没有错的。它只是为删除按钮添加弹出确认窗口的功能而已。
报错的内容是:指定的参数已超出有效值的范围。参数名:INDEX疑惑不解,请高手赐教。
解决方案 »
- 大哥哥们,请教一个关于Asp.net 连接 Oracle 数据库 问题~~
- ASP.NET GridView模板控件问题
- SLDPRT扩展名怎么设置MIME映射
- 为什么 控件拖不动?
- 初学webForm●●●Gridview绑定数据后为什么SelectedIndex始终为 -1 ????●●●
- 连接mysql的问题,没分了,请大家帮帮忙~~谢谢了
- 关于存储过程的一个问题!
- 一个比较简单的问题(对文件的操作)
- 为什么我的TREEVIEW显示不正常
- (急!)同一台服务器的两上项目怎么互相传递参数?? (不用windows.open)
- GridView排序!!!
- 请教:怎样给在自定义类中动态添加的按钮控件响应事件函数??
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#66ccff'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
if(e.Row.RowState==DataControlRowState.Edit)
((LinkButton)(e.Row.Cells[5].Controls[0])).Attributes.Add("onclick", "return confirm('确认删除?');");
}
还有在编辑状态下有几个按钮?再确定是Controls[0]还是Controls[1]