在datagrid中删除选中的记录,在线等
如图datagrid中每条记录前面有一个CheckBox
在datagrid中的FooterTemplate里面有一删除按钮,CommandName为delselect。
在dgalledit_ItemCommand事件里面
C# code
switch (e.CommandName)
{
……
case "delselect":
{
//这里应该写什么语句删除选中的记录
break;
}
}
------解决方案--------------------
给你谢代码参考,下面为批量update的,你改为delete的就是了:
**.aspx页面:
<asp:GridView ID="GridView1" runat="server" Width="923px" AutoGenerateColumns="False" DataKeyNames="users_Id">
<Columns>
<asp:TemplateField FooterText="全选" HeaderText="选择"><HeaderTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True" Text="全选" OnCheckedChanged="CheckAll" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" Font-Names="宋体" Font-Size="9pt" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="users_Name" HeaderText="帐号" />
<asp:BoundField DataField="users_FullName" HeaderText="客户经理姓名" />
<asp:BoundField DataField="users_Sex" HeaderText="性别" />
<asp:BoundField HeaderText="客户经理Email" DataField="users_Email" />
<asp:BoundField HeaderText="客户经理电话" DataField="users_Tel" />
<asp:BoundField DataField="users_Department" HeaderText="所属分部" />
<asp:BoundField DataField="users_Service" HeaderText="服务对象" />
<asp:BoundField DataField="users_Key" HeaderText="审批状态" />
</Columns>
</asp:GridView>
**.aspx.cs页面:
#region GridView全选/取消
protected void CheckAll(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)sender;
if (cb.Text == "全选")
{
foreach (GridViewRow gv in this.GridView1.Rows)
{
CheckBox cd = (CheckBox)gv.FindControl("CheckBox1");
cd.Checked = cb.Checked;
cb.Text = "取消";
}
}
else
{
cb.Text = "取消";
foreach (GridViewRow gv in this.GridView1.Rows)
{
CheckBox cd = (CheckBox)gv.FindControl("CheckBox1");
cd.Checked = cb.Checked;
cb.Text = "全选";
}
}
}
#endregion
#region 客户经理审批(通过)
protected void Pass_Click(object sender, ImageClickEventArgs e)
{
bool success = false;
foreach (GridViewRow gv in GridView1.Rows)
{
CheckBox cb = (CheckBox)gv.FindControl("CheckBox1");
if (cb.Checked)
{
int index = gv.RowIndex;
DataKey key = this.GridView1.DataKeys[index];//获取主键
int users_Id = Convert.ToInt32(key.Values["users_Id"]);
Hashtable ht = new Hashtable();
ht.Add("users_Key", SQLStringFormat.GetQuotedString("已通过"));
Manager manager = new Manager();
suc