我想代表 id 从数据列表中删除图像,但此代码不起作用错误:索引超出范围。必须是非负数且小于集合的大小。参数名称:索引
public void show_top_one()
{
BusinessLogic b1 = new BusinessLogic();
string query = "select txt_img_name from tbl_gallery2";
DataSet ds = b1.GetDataSet(query);
DataList1.DataSource = ds.Tables[0];
DataList1.DataBind();
}
protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
{
BusinessLogic b1 = new BusinessLogic();
int id = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex]);
string query = "Delete from tbl_gallery2 where id='"+id+"'";
b1.ExecuteQuery(query);
show_top_one();
}
}