日期:2014-05-18 浏览次数:20543 次
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always"> <ContentTemplate> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="5" Style="text-align: center" Width="100%" OnRowCommand="GridView1_RowCommand"> <Columns> <asp:BoundField DataField="Account" HeaderText="账号" ReadOnly="true" /> <asp:TemplateField HeaderText="操作"> <ItemTemplate> <asp:LinkButton ID="btndelete" runat="server" CommandName="Delete" Text="删除" CommandArgument='<%#Eval("Account") %>' OnClientClick="return confirm('删除后将无法恢复,确认要删除此行信息吗?')"></asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> <HeaderStyle CssClass="tbg1" /> </asp:GridView> </ContentTemplate> </asp:UpdatePanel>
//账号添加正常,列表会刷新,消息通知也会正常弹出 protected void btnAdd_Click(object sender, EventArgs e) { string account = this.txtAddAcount.Text.Trim(); SqlParameter[] p = new SqlParameter[] { new SqlParameter("@account", account) }; string sql = "insert into account values(@account)"; if (baseclass.ExecuteSql(sql, p) > 0) { BindGrid(); ShowMessage("账号添加成功!"); Log.WriteLog("用户:【" + model.Username + "】添加账号【" + account + "】"); } else { ShowMessage("系统忙,请稍后再试!"); Log.WriteLog("用户:【" + model.Username + "】添加账号【" + account + "】失败"); } } //删除不正常,数据删除了,但列表没有刷新,消息也没有弹出,页面没任何反应 //单步调试,发现代码运行正常,就是页面没反应 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "delete") { string account = e.CommandArgument.ToString().Trim(); string sql = "delete accounts where Account = @account"; SqlParameter[] p = new SqlParameter[] { new SqlParameter("@account", account) }; if (baseclass.ExecuteSql(sql, p) > 0) { BindGrid(); //刷新GridView1 ShowMessage("账号删除成功!"); Log.WriteLog("用户:【" + model.Username + "】删除账号【" + account + "】"); } else { ShowMessage("系统忙,请稍后再试!"); Log.WriteLog("用户:【" + model.Username + "】删除账号【" + account + "】失败"); } } }