我在DELETE按钮列编码如下
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName=="Delete")
{
dbutil dtl=new dbutil();
this.DataGrid1.DataKeyField="itemid";
string itemid=this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
this.Label1.Text=itemid;
SqlCommand cmd2=new SqlCommand();
cmd2.Connection=new SqlConnection(dtl.constr());
string sqlstr2="delete from lineitem where orderid="+Page.Session["orderid"]+" AND itemid="+itemid+"";
cmd2.CommandText=sqlstr2;
cmd2.CommandType=CommandType.Text;
cmd2.Connection.Open();
cmd2.ExecuteNonQuery();
cmd2.Connection.Close();
SqlCommand cmd4=new SqlCommand();
cmd4.Connection=new SqlConnection(dtl.constr());
string sqlstr4="select price,quantity,item.itemid from lineitem ,item where orderid="+Page.Session["orderid"]+"AND item.itemid=lineitem.itemid";
cmd4.CommandText=sqlstr4;
cmd4.CommandType=CommandType.Text;
SqlDataAdapter da4=new SqlDataAdapter(cmd4);
DataSet ds4=new DataSet();
da4.Fill(ds4);
this.DataGrid1.DataSource=ds4.Tables[0];
this.DataGrid1.DataBind();
}
运行时显示错误,是E.ITEM.ITEMIDEX超出了索引范围,请高手们帮忙回答一下
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName=="Delete")
{
dbutil dtl=new dbutil();
this.DataGrid1.DataKeyField="itemid";
string itemid=this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
this.Label1.Text=itemid;
SqlCommand cmd2=new SqlCommand();
cmd2.Connection=new SqlConnection(dtl.constr());
string sqlstr2="delete from lineitem where orderid="+Page.Session["orderid"]+" AND itemid="+itemid+"";
cmd2.CommandText=sqlstr2;
cmd2.CommandType=CommandType.Text;
cmd2.Connection.Open();
cmd2.ExecuteNonQuery();
cmd2.Connection.Close();
SqlCommand cmd4=new SqlCommand();
cmd4.Connection=new SqlConnection(dtl.constr());
string sqlstr4="select price,quantity,item.itemid from lineitem ,item where orderid="+Page.Session["orderid"]+"AND item.itemid=lineitem.itemid";
cmd4.CommandText=sqlstr4;
cmd4.CommandType=CommandType.Text;
SqlDataAdapter da4=new SqlDataAdapter(cmd4);
DataSet ds4=new DataSet();
da4.Fill(ds4);
this.DataGrid1.DataSource=ds4.Tables[0];
this.DataGrid1.DataBind();
}
运行时显示错误,是E.ITEM.ITEMIDEX超出了索引范围,请高手们帮忙回答一下
解决方案 »
- 替换flash文件的代码
- 在程序的任意位置怎样获取当前vs插件的 _applicationObject;(vs窗口的DTE2对象)?
- 关于C#中dateTimePicker sql语句日期查询语句
- 页面设计问题 怎么才能点击一个超链接 让他跳到你所想跳的 本页面某个地方
- 正则表达式提取html标签 为什么<font>失败
- c# 如何通过数据源绑定到新的数据成员?
- “'*' 附近有语法错误。 必须声明标量变量” 的错误!
- 读取打印机的问题?(打印问题 ?)
- GridView 中添加水平线
- 数据库有个字段ID,要以这个字段排序并且得到不重复的ID的值,用什么方法呢?用sort好像实现不了,急……
- 怎样判断 剪切板 为空?怎样设置剪切板为空?
- button
索引超出范围。必须为非负值并小于集合大小。参数名: index
里面就一句出错string itemid=this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString();应该就这一句了吧,为什么e.Item.ItemIndex会不行呢