也是关于Gridview的问题,谢谢!

yighter 2007-09-08 11:26:33
html部分:
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" Width="800px" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand" >
<Columns>
<asp:TemplateField HeaderText="用户操作">
<ItemTemplate>
<a href='EditUser.aspx?UserID=<%#DataBinder.Eval(Container.DataItem,"UserID") %>'>编辑</a>   <a href='EditPwd.aspx?UserID=<%#DataBinder.Eval(Container.DataItem,"UserID") %>'>修改密码</a>   
<asp:Button ID="Button3" runat="server" Text="删除用户" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"UserID") %>' CommandName="delete" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="管理员设置">
<ItemTemplate>
<asp:Button ID="Button2" runat="server" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"UserID") %>' Text='<%#(bool)DataBinder.Eval(Container.DataItem,"IsAdmin")==true ? "取消管理员":"设为管理员" %>' CommandName="admin"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

C#部分:
protected void GridView1_RowCommand(object sender,GridViewCommandEventArgs e)
{
string comname = e.CommandName;
int nUserID = -1;
if (Int32.TryParse(e.CommandArgument.ToString(), out nUserID) == false || comname == "")
{
return;
}
IUser user = new User();
switch (comname)
{
case "delete":
{
Button button = (Button)e.CommandSource;
if (button == null) { break; }
user.deleteuser(nUserID);
Response.Write("<script>alert('" + "删除用户成功!" + "')</script>");
binduserdata();
break;
}
case "admin":
{
Button button = (Button)e.CommandSource;
if (button == null) { break; }
user.updateuseradmin(nUserID, button.Text == "取消管理员" ? false : true);
Response.Write("<script>alert('" + "设置管理权限成功!" + "')</script>");
binduserdata();
break;
}
default: break;


}
}

问题:
点击取消管理员的按扭,操作结果正确,但是点击删除用户的按迅就了出现问题了。
错误码:
GridView“GridView1”激发了未处理的事件“RowDeleting”。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Web.HttpException: GridView“GridView1”激发了未处理的事件“RowDeleting”。

源错误:

执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。

堆栈跟踪:


[HttpException (0x80004005): GridView“GridView1”激发了未处理的事件“RowDeleting”。]
System.Web.UI.WebControls.GridView.OnRowDeleting(GridViewDeleteEventArgs e) +325
System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) +732
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +1067
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +163
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +119
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +107
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +179
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3837


谢谢~~
...全文
116 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
yighter 2007-09-08
  • 打赏
  • 举报
回复
而且在数据库里对应的内容也被删除了

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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