LinkButton操作方法
前台
<asp:LinkButton runat="server" ID="LinkBtnDel" CommandArgument='<%# Eval("Autoid") %>' CommandName="del" OnClick="LinkBtnDel_Click"></asp:LinkButton>
后台
protected void LinkBtnDel_Click(object sender, EventArgs e)
{
if (e.CommandName=="del")
{
int pid = Convert.ToInt32(e.CommandArgument.ToString());
this.Shop.Remove(pid);
this.Shop.Display(this.Repeater1);
this.HDTotal.Value = this.Shop.Total.ToString();
StringBuilder builder = new StringBuilder();
builder.Append(this.HDTotal.Value.ToString());
this.ZJ.InnerHtml = builder.ToString();
}
}
但是提示
编译器错误消息: CS0117: “System.EventArgs”并不包含“CommandName”的定义
已经有CommandName定义del了。
------解决方案--------------------<asp:Button ID="btn_delete" runat="server" CssClass="btn_Delete1" ToolTip="删除" Visible="<%#opVisible%>"
OnClientClick="return confirm('确定要删除吗?')" CommandArgument='<%# Eval("id") %>' onclick="btn_delete_Click" />