在asp中如何用一个button删除多条勾选的记录(gridview中的)?

yaokaipeng 2007-01-04 02:37:37
请各位大侠给出cs中的代码,谢谢
...全文
366 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yaokaipeng 2007-01-04
  • 打赏
  • 举报
回复
谢谢各位,尤其是风车车,那么详细,偶也是四川的哈~~
xray2005 2007-01-04
  • 打赏
  • 举报
回复
HTML,gridview中的ItemTemplate代码
<ItemTemplate>
<table border="0" cellpadding="0" cellspacing="0" width="100%" >
<tr align="left" style="font-weight:normal;font-size:9pt" valign="middle">
<td width="4%" align="center">
<input type="checkbox" id="selectedchkbox" value='<%#DataBinder.Eval(Container.DataItem,"InfoID") %>' runat="server" /></td>
<td width="4%" align="center> </td>
<td align="left" valign="middle" width="35%">
<a href="LookMail.aspx?MailId=<%#DataBinder.Eval(Container.DataItem,"MailID")%>" target="_self"><font color="#9933ff"><%DataBinder.Eval(Container.DataItem, "Subject")%></font></a>
</td>
<td align="center" valign="middle" width="15%">
<%#DataBinder.Eval(Container.DataItem,"UserID") %>
</td>
<td align="center" valign="middle" width="15%">
<%=ReceiversNamelbstring%>
</td>
<td align="center" valign="middle" width="15%">
<%#DataBinder.Eval(Container.DataItem, "SendDate", "{0:yyyy-MM-dd HH:mm}")%>
</td>

<td align="center" valign="middle" width="12%">

</td>
</tr>
</table>
</ItemTemplate>
xray2005 2007-01-04
  • 打赏
  • 举报
回复
LZ,给你看看我的cs代码:
//删除选中按钮事件
protected void deleteSelectedBtn_Click(object sender, EventArgs e)
{
int intFlag=0;
for (int i = 0; i < this.ShowMailGridView.Rows.Count; i++)
{
GridViewRow row = this.ShowMailGridView.Rows[i];
HtmlInputCheckBox selectedChkbox=(HtmlInputCheckBox)row.FindControl("selectedchkbox") as System.Web.UI.HtmlControls.HtmlInputCheckBox;
if (selectedChkbox !=null && selectedChkbox.Checked)
{
int InfoId = Convert.ToInt32(selectedChkbox.Value);
intFlag = Mail.DeleteMail(InfoId);
}
}
if (intFlag > 0)
{
thisShowMailGridViewDataBind();
}

}
//删除全部按钮事件
protected void deleteAllBtn_Click(object sender, EventArgs e)
{
int intFlag = 0;
for (int i = 0; i < this.ShowMailGridView.Rows.Count; i++)
{
GridViewRow row = this.ShowMailGridView.Rows[i];
HtmlInputCheckBox selectedChkbox=(HtmlInputCheckBox)row.FindControl("selectedchkbox") as System.Web.UI.HtmlControls.HtmlInputCheckBox;
if(selectedChkbox !=null)
{
int InfoId = Convert.ToInt32(selectedChkbox.Value);
intFlag = Mail.DeleteMail(InfoId);
}
}
if (intFlag > 0)
{
thisShowMailGridViewDataBind();
}


}
xbugirl 2007-01-04
  • 打赏
  • 举报
回复
string del = "";
把勾选的数据全扔进 del 里。然后
delete from 表 Where id in ("+del+")

phommy 2007-01-04
  • 打赏
  • 举报
回复
逐条删肯定不如用in子句删... 不过我也不会-_-
fffxcg 2007-01-04
  • 打赏
  • 举报
回复
循环逐条删除???
等待高手答案.....

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧