gridview更新错误 指定的参数已超出有效值的范围。参数名:index

seles seles 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
更新错误,不知道为什么,下面是详细信息:
用户代码未处理 System.ArgumentOutOfRangeException
Message="指定的参数已超出有效值的范围。\r\n参数名: index"
Source="System.Web"
ParamName="index"
StackTrace:
在 System.Web.UI.ControlCollection.get_Item(Int32 index)
在 admin_Message_management.GridView1_RowUpdating(Object sender, GridViewUpdateEventArgs e) 位置 f:\myweb\admin\Message management.aspx.cs:行号 50
在 System.Web.UI.WebControls.GridView.OnRowUpdating(GridViewUpdateEventArgs e)
在 System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation)
在 System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup)
在 System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e)
在 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
在 System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e)
在 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
在 System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
在 System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
在 System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
在 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
在 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


更新代码如下:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string Name = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
string Zhuti = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
string Qq = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
string Email= ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim();
string Content = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim();
string Time=((TextBox )(GridView1.Rows [e.RowIndex ].Cells[6].Controls [0])).Text .ToString ().Trim();
SqlConnection sqlcon=new SqlConnection ();
sqlcon .ConnectionString ="server=(local);uid=sa;pwd=sa;database=post";
sqlcon .Open ();
string sqlstr = "update post set name='" +Name + "',zhuti='"+ Zhuti + "',qq='"+Qq + "' ,email='"+Email +"',content='"+Content +"',time='" +Time +"' where id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";

SqlCommand sqlcom = new SqlCommand(sqlstr, sqlcon);
sqlcom.ExecuteNonQuery();
GridView1.EditIndex = -1;
sqlcon.Close();
DataBind();


}
请各位大侠给我看看,我都快疯了。
...全文

相关推荐

Mabatis错误提示Parameter index out of range的处理方法

主要介绍了Mabatis错误提示Parameter index out of range 的处理方法,本文给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下

weixin_38671048

gridview自动编号及更新操作

通过过程来实现gridview自动编号及更新操作,操作的是SQL2005数据库

信息尽有

Android应用因索引超出范围问题而崩溃。 请帮我解决这个问题

Android仍基于Java语言,因此例外通常是应用程序中以Java为主题的问题。 “索引超出范围”表示您正在尝试引用当前集合内不可用的元素。 看看异常本身,索引...

weixin_38611230

利用jQuery及AJAX技术定时更新GridView的某一列数据

看到一个问题:定时更新GridView的某一列中的状态文本。马上就有了思路:GridView最后会生成表格,所以我们在页面中通过Ajax更新表格的列,从而达到ajax更新GridView的效果。 具体实现: 准备一个xml文件,用于存储要更新的数据,在页面中启动一个定时器,每隔5秒钟调用一个函数,函数里边通过$.ajax获取xml中的数据,解析xml,遍历表格行,匹配要更新的数据,更新。 getuserlist.xml 定义一个UserList的根节点,下边每个UserItem对应一条数据,UID可以理解成主键,UStatus是最新的状态。 <?xml version="1.0" enco

weixin_38733885

GridView控件行上移、下移

GridView控件行数据上移、下移的实现,Visual Studio2010、Sqlserver2008。

netjunlian
评论 6
收藏 已收藏
分享
返回顶部
seles
C# 111,129 成员 642,538 内容