首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

Gridview删除行记要

2012-09-15 
Gridview删除行记录//删除事件protected void LinkButton2_Click(object sender, EventArgs e){foreach (G

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();

热点排行