Gridview删除行记录
//删除事件
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();