索引超出范围。必须为非负值并小于集合大小的问题 求高手解决 20

索引超出范围。必须为非负值并小于集合大小。参数名:index异常详细信息:System.ArgumentOutOfRangeException:索引超出范围。必须为非负值... 索引超出范围。必须为非负值并小于集合大小。
参数名: index

异常详细信息: System.ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。
参数名: index

源错误:

行 46: protected void gvOrderInfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
行 47: {
行 48: string sqlstr = "delete from tb_OrderInfo where OrderID='" + gvOrderInfo.DataKeys[e.RowIndex].Value + "'";
行 49: sqloperate.DataCom(sqlstr);
行 50: Response.Redirect("OrderManage.aspx");

后台代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class AdminManage_OrderManage : System.Web.UI.Page
{
SqlOperate sqloperate = new SqlOperate();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string sqlstr = "select distinct OrderMember from tb_OrderInfo";
//gvOrderInfo.DataKeyNames = new string[] { "OrderID" };
sqloperate.gvDataBind(gvOrderInfo, sqlstr);
}
}
protected void btnSel_Click(object sender, EventArgs e)
{
if (txtKey.Text == "")
{
string sqlstr = "select distinct OrderMember from tb_OrderInfo";
sqloperate.gvDataBind(gvOrderInfo, sqlstr);
}
else
{
string sqlstr = "select distinct OrderMember from tb_OrderInfo where "
+ ddlCondition.SelectedValue + " like '%" + txtKey.Text.Trim() + "%'";
sqloperate.gvDataBind(gvOrderInfo, sqlstr);
}
}
protected void gvOrderInfo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((LinkButton)(e.Row.Cells[2].Controls[0])).Attributes.Add("onclick", "return confirm('确定要删除吗?')");
}
}
protected void gvOrderInfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string sqlstr = "delete from tb_OrderInfo where OrderID='" + gvOrderInfo.DataKeys[e.RowIndex].Value + "'";
sqloperate.DataCom(sqlstr);
Response.Redirect("OrderManage.aspx");
}
protected void gvOrderInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvOrderInfo.PageIndex = e.NewPageIndex;
string sqlstr = "select distinct OrderMember from tb_OrderInfo where "
+ ddlCondition.SelectedValue + " like '%" + txtKey.Text.Trim() + "%'";
sqloperate.gvDataBind(gvOrderInfo, sqlstr);
}
protected void gvOrderInfo_SelectedIndexChanged(object sender, EventArgs e)
{

}
}
怎么绑定
展开
 我来答
百度网友95e6689
2011-04-03 · TA获得超过2769个赞
知道小有建树答主
回答量:348
采纳率:0%
帮助的人:336万
展开全部
OrderID没绑定
追问
怎么绑定啊
追答
DataKeyNames="OrderID"
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式