//删除事件
protected void LinkButton2_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in this.GridView1.Rows)
{
CheckBox CheckRow = (CheckBox)row.FindControl("CheckRow");
if (CheckRow.Checked)
{
string id = GridView1.DataKeys[row.RowIndex].Value.ToString();
string sql = "delete from money_info where Id='" + id + "'";
Common common = new Common();
common.ExecuteNonQuery(sql);
DbTools.MsgBox("信息删除成功!");
}
}
}//页面前台
<asp:TemplateField>
<HeaderTemplate>
<input type="checkbox" id="Check" onclick="CheckAll(this)" title="全选/全不选" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckRow" runat="server" />
</ItemTemplate>
<HeaderStyle Width="20px" />
</asp:TemplateField>//问题
我一点击删除按钮,页面就好像刷新了一下,所要删除的一行记录删不掉。
protected void LinkButton2_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in this.GridView1.Rows)
{
CheckBox CheckRow = (CheckBox)row.FindControl("CheckRow");
if (CheckRow.Checked)
{
string id = GridView1.DataKeys[row.RowIndex].Value.ToString();
string sql = "delete from money_info where Id='" + id + "'";
Common common = new Common();
common.ExecuteNonQuery(sql);
DbTools.MsgBox("信息删除成功!");
}
}
}//页面前台
<asp:TemplateField>
<HeaderTemplate>
<input type="checkbox" id="Check" onclick="CheckAll(this)" title="全选/全不选" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckRow" runat="server" />
</ItemTemplate>
<HeaderStyle Width="20px" />
</asp:TemplateField>//问题
我一点击删除按钮,页面就好像刷新了一下,所要删除的一行记录删不掉。
点击删除后,打开数据库,看看是不是真的删除了
因为你刚刚点了删除之后 其实是删除成功了的 只是数据库需要重新绑定
绑定就可以看到效果了
this.GridView1.DataSource=...
this.GridView1.DataBind();
if (IDList != "" && IDList != null)
{}
用这种方法试下