求教:VS 2005的GridView模板项中使用自定义按钮删除记录 数据库中的表Reply的主键是replyID,外键是cardID。请问要在GridView模板项中使用自定义按钮删除记录,应该怎么做? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 编辑列->添加一个ButtonField 设他的CommandName 为一个名字“del”在GridView 中的RowCommand事件中if(e.commandName=="del"){ 这儿写你要执行的东西} 对不起,是我表达不清楚,因为要控制格式,所以要使用模板项,但是在添加了Button按钮后,不知道接着Button控件的代码应该怎么写,特别是怎么取得所在行的replyID Button控件的代码应该写执行删除的语句了,你上面说的应该是主从表的删除了,那应该把子表的删除语句放在前面,主表的删除语句放在后面执行。 你在GridView里的DataKeyNames="replyID" 后台 GridView.DataKeys[当前行索引].Value.ToString();这样你Button里就可以取到呢replyID的值了 <asp:TemplateField HeaderText="Delete"> <ItemTemplate> <asp:ImageButton ID="IBtnDelete" runat="server" ImageUrl="~/images/toolBar/delete.gif" CommandArgument='<%# Eval("RequList_id") %>' ForeColor="blue" CommandName="Delete" OnCommand="DeleteClick" OnClientClick="return confirm('确定删除吗? 数据一旦删除将无法恢复!!');" /> </ItemTemplate> <ItemStyle Width="50px" /> <HeaderStyle HorizontalAlign="Center" /> </asp:TemplateField> protected void DeleteClick(object sender, CommandEventArgs e) { if (e.CommandName.Equals("Delete")) { int id = Convert.ToInt32(e.CommandArgument.ToString()); ONETIMS.BusinessRules.FAEManager.FAE_RequList bill = new ONETIMS.BusinessRules.FAEManager.FAE_RequList(); int State = Convert.ToInt32(bill.ReturnStateById(id)); if (State != 1) { Web.Utility.JavascriptDeal.AjaxShow("对不起该申请已经在处理当中不能删除!"); } else { bill.Delete(id); } this.BindGridView(); } } 查看 查询 excel MVC框架下,共通的javascript方法,放在什么地方比较好??? 求:网页中使用ActiveX的例子 求助!用asp.net自带的CreateUserWizard生成用户报错! 关于嵌入式框架 急!!!!!!!为什么用TreeView绑定XML文件时总是提示:根级别上的数据无效 asp中输出数据库自增数据问题 DataSet 的绑定问题 ASP.net 使用慧都控件部署IIS后,显示不出样式 web自定控件问题,怎样保持状态? TextBox 字体滚动 master的header问题
在GridView 中的RowCommand事件中
if(e.commandName=="del")
{
这儿写你要执行的东西
}
后台 GridView.DataKeys[当前行索引].Value.ToString();
这样你Button里就可以取到呢replyID的值了
<ItemTemplate>
<asp:ImageButton ID="IBtnDelete" runat="server" ImageUrl="~/images/toolBar/delete.gif"
CommandArgument='<%# Eval("RequList_id") %>' ForeColor="blue" CommandName="Delete"
OnCommand="DeleteClick" OnClientClick="return confirm('确定删除吗? 数据一旦删除将无法恢复!!');" />
</ItemTemplate>
<ItemStyle Width="50px" />
<HeaderStyle HorizontalAlign="Center" />
</asp:TemplateField>
protected void DeleteClick(object sender, CommandEventArgs e)
{
if (e.CommandName.Equals("Delete"))
{
int id = Convert.ToInt32(e.CommandArgument.ToString());
ONETIMS.BusinessRules.FAEManager.FAE_RequList bill = new ONETIMS.BusinessRules.FAEManager.FAE_RequList();
int State = Convert.ToInt32(bill.ReturnStateById(id));
if (State != 1)
{
Web.Utility.JavascriptDeal.AjaxShow("对不起该申请已经在处理当中不能删除!");
}
else
{
bill.Delete(id);
}
this.BindGridView();
}
}