//删除数据
protected void btnDeletes_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in gvContent.Rows)
{
CheckBox checkbox = (CheckBox)row.FindControl("CheckBox1");
if (checkbox.Checked)
{
string sql = "delete from newstype where typeid=@typeid";
SqlParameter p = new SqlParameter("typeid", SqlDbType.Int);
p.Value = int.Parse(checkbox.ToolTip.ToString());
bool flag = Conn.Insert(sql, p);
}
}
Response.Redirect("HhkjObjectManager.aspx");
}
运行的时候,先选中然后点删除按钮没有反应,调式的时候checkbox.Checked永远都是false,不知道是什么问题.
protected void btnDeletes_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in gvContent.Rows)
{
CheckBox checkbox = (CheckBox)row.FindControl("CheckBox1");
if (checkbox.Checked)
{
string sql = "delete from newstype where typeid=@typeid";
SqlParameter p = new SqlParameter("typeid", SqlDbType.Int);
p.Value = int.Parse(checkbox.ToolTip.ToString());
bool flag = Conn.Insert(sql, p);
}
}
Response.Redirect("HhkjObjectManager.aspx");
}
运行的时候,先选中然后点删除按钮没有反应,调式的时候checkbox.Checked永远都是false,不知道是什么问题.
if (!this.IsPostBack)
{}
这里面,点按钮的时候又重新绑定了
{
if(!IsPostback())
{
BindData();//绑定GridView的数据源
}
}protected void btnDeletes_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in gvContent.Rows)
{
CheckBox checkbox = (CheckBox)row.FindControl("CheckBox1");
if (checkbox.Checked)
{
string sql = "delete from newstype where typeid=@typeid";
SqlParameter p = new SqlParameter("typeid", SqlDbType.Int);
p.Value = int.Parse(checkbox.ToolTip.ToString());
bool flag = Conn.Insert(sql, p);
}
}
BindData();//重新绑定
Response.Redirect("HhkjObjectManager.aspx");
}
if (!this.IsPostBack)
{}
这里面,点按钮的时候又重新绑定了
因为gridview用了分页的功能,如果使用上面的代码,是可以删除但是翻到下一页的时候就不会显示数据了.