参数超出有效范围

sssolweb_007 2010-12-27 09:56:41
异常信息:
指定的参数已超出有效值的范围。
参数名: index

GridView的删除事件。
protected void GridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
BLL_FlightTb Flight = new BLL_FlightTb();
string flightid=((TextBox)(GridView.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString().Trim();

异常信息:
指定的参数已超出有效值的范围。
参数名: index


Flight.Flight_Delete(flightid);
this.bind();
}

前台GridView的代码是这样的:
<asp:GridView ID="GridView" runat="server" CellPadding="2"
ForeColor="#333333" AutoGenerateColumns="False" CellSpacing="2"
onrowcancelingedit="GridView_RowCancelingEdit"
onrowdeleting="GridView_RowDeleting" onrowediting="GridView_RowEditing"
onrowupdating="GridView_RowUpdating">

<FooterStyle BackColor="#990000" Font-Bold="true" ForeColor="White" />
<Columns>
<asp:BoundField DataField="FlightID" HeaderText="航班号" ReadOnly="true"/>
<asp:BoundField DataField="FlightTime" HeaderText="航班时间" />
<asp:BoundField DataField="FlightStart" HeaderText="起始地点"/>
<asp:BoundField DataField="FlightEnd" HeaderText="到达地点"/>
<asp:BoundField DataField="Launch" HeaderText="起飞时间"/>
<asp:BoundField DataField="Land" HeaderText="到达时间"/>
<asp:BoundField DataField="MidStation" HeaderText="中间站" />
<asp:BoundField DataField="Capacity" HeaderText="乘客量" />
<asp:BoundField DataField="Remain" HeaderText="空票数" />
<asp:BoundField DataField="Price" HeaderText="票价" />
<asp:CommandField HeaderText="选择" ShowSelectButton="true" />
<asp:CommandField HeaderText="编辑" ShowEditButton="true" />
<asp:CommandField HeaderText="删除" ShowDeleteButton="true" />
</Columns>
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="true" ForeColor="White"/>
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left"/>
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
...全文
197 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
wycoo 2011-11-22
  • 打赏
  • 举报
回复
我想在 delete gridview 的单元行中 不能用(TextBox)强制转换,
直接GridView.Rows[e.RowIndex].Cells[0].Text 就可以了
zhang_456 2010-12-27
  • 打赏
  • 举报
回复
调试下就一目了然.
wuyq11 2010-12-27
  • 打赏
  • 举报
回复
单步看看e.RowIndex
GridView.Rows[e.RowIndex].Cells[0].Text
jcx396158820 2010-12-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 maco_wang 的回复:]
http://blog.sina.com.cn/s/blog_5abd92710100ka6l.html
http://dengning2005.blog.163.com/blog/static/2816427120083283281628/
[/Quote]
+1
wangkerry123 2010-12-27
  • 打赏
  • 举报
回复
列数与绑定的数不一样。导致的,检查一下你的列是不是和后台绑定的列数目一样。
叶子 2010-12-27
  • 打赏
  • 举报
回复
http://blog.sina.com.cn/s/blog_5abd92710100ka6l.html
http://dengning2005.blog.163.com/blog/static/2816427120083283281628/
Rock870210 2010-12-27
  • 打赏
  • 举报
回复
string flightid=GridView1.Rows[e.RowIndex].Cells[0].Text;试试
<asp:GridView ID="GridView" runat="server" CellPadding="2"
ForeColor="#333333" AutoGenerateColumns="False" CellSpacing="2"
GridView是一个对象,命名最好不要与对象重复。起名gv_名称或者直接用GridView1都行
chen_ya_ping 2010-12-27
  • 打赏
  • 举报
回复
调试一下看看 e.RowIndex,是多少。看看它的数值是多大。
wangchangming 2010-12-27
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20101226/13/4daace51-dd3a-49c3-ae2e-839ecfc9635a.html?47862
村长_乐 2010-12-27
  • 打赏
  • 举报
回复
调试一下,看看e.RowIndex
默认是从0开始的,你数数看对不
lovexiu0924 2010-12-27
  • 打赏
  • 举报
回复
你把第一列的第一个控件转换成TextBox 但是那个不是TextBox控件啊 这里有点问题吧

直接 GridView.Rows[e.RowIndex].Cells[0].Text应该可以的
不行的话 单步
sssolweb_007 2010-12-27
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 wuyq11 的回复:]
单步看看e.RowIndex
GridView.Rows[e.RowIndex].Cells[0].Text
[/Quote]

就是这样的。。。

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧