首页上一页 1 下一页尾页 1 条记录 1/1页
gridview删除问题
发表在ASP.NET图书答疑
2009-05-09
是否精华
是
否
版块置顶:
是
否
asp.net程序开发范例宝典一书中Ex04_23一例,删除功能好用,可是我加上查询条件后,经常提示错误,提示如下
"用户代码未处理,ArgumentOutOfRangeException 索引起出范围,必须为非负值并小于集合大小,参数名为:index"
我觉得也是参数出界了,不知怎么改
下面是我作的多重查询条件,我把原来的page_load里的 if (!IsPostBack)
{
bind();
}
删除了
我是想经过查询后结果显示在GRIDVIEW里,有编辑删除功能
protected void Button2_Click(object sender, EventArgs e)
{
try
{
string Sql = @" select * from tb_Member where 1=1 ";
if (CheckBox1.Checked)
{
Sql = Sql + "and name like '%" + yw.Text + "%' ";
}
if (CheckBox2.Checked)
{
Sql = Sql + "and sex like '%" + ht.Text + "%' ";
}
if (CheckBox3.Checked)
{
Sql = Sql + "and nplace like '%" + bh.Text + "%' ";
}
Session["sql"] = Sql;
//this.bind();
sqlcon = new SqlConnection(strCon);
SqlDataAdapter myda = new SqlDataAdapter(Sql, sqlcon);
DataSet myds = new DataSet();
sqlcon.Open();
myda.Fill(myds);
GridView1.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
GridView1.DataSource = myds;
GridView1.DataBind();
sqlcon.Close();
}
catch
{
Response.Write("<script language=javascript>alert('条件错误!')</script>");
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
这段代码,我试过,没有问题,请指点一下
"用户代码未处理,ArgumentOutOfRangeException 索引起出范围,必须为非负值并小于集合大小,参数名为:index"
我觉得也是参数出界了,不知怎么改
下面是我作的多重查询条件,我把原来的page_load里的 if (!IsPostBack)
{
bind();
}
删除了
我是想经过查询后结果显示在GRIDVIEW里,有编辑删除功能
protected void Button2_Click(object sender, EventArgs e)
{
try
{
string Sql = @" select * from tb_Member where 1=1 ";
if (CheckBox1.Checked)
{
Sql = Sql + "and name like '%" + yw.Text + "%' ";
}
if (CheckBox2.Checked)
{
Sql = Sql + "and sex like '%" + ht.Text + "%' ";
}
if (CheckBox3.Checked)
{
Sql = Sql + "and nplace like '%" + bh.Text + "%' ";
}
Session["sql"] = Sql;
//this.bind();
sqlcon = new SqlConnection(strCon);
SqlDataAdapter myda = new SqlDataAdapter(Sql, sqlcon);
DataSet myds = new DataSet();
sqlcon.Open();
myda.Fill(myds);
GridView1.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
GridView1.DataSource = myds;
GridView1.DataBind();
sqlcon.Close();
}
catch
{
Response.Write("<script language=javascript>alert('条件错误!')</script>");
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
这段代码,我试过,没有问题,请指点一下