我有一个 GridView。我在这个 GV 中显示系统中的所有用户,并且我有一个按钮可以通过将表中已删除的列更新为 1 来删除用户。
<asp:GridView ID="GridView1" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging"
PageSize="20" runat="server" OnRowCommand="GridView1_OnRowCommand"
DataKeyNames="Id, Email" EnableViewState="false" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="buttonDelete" runat="server" CommandName="Remove" Text="Delete"
CommandArgument='<%# Eval("Id") + ";" +Eval("Email")%>'
OnClientClick='return confirm("Are you sure you want to delete this user?");' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
<asp:BoundField DataField="Email" HeaderText="Email" />
<asp:BoundField DataField="Status" HeaderText="Status" />
<asp:BoundField DataField="Location" HeaderText="Location" />
</Columns>
</asp:GridView>
protected void GridView1_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
string cmdName = e.CommandName;
string[] commandArgs = e.CommandArgument.ToString().Split(new char[] { ';' });
string UserRowID = commandArgs[0];
string Email = commandArgs[1];
string sql = "UPDATE USERS " +
"SET [Deleted]= 1" +
"WHERE ROWID= " + UserRowID;
DataTable table = PublicClass.ExeSql_Table(sql, "Utility");
GridView1.DataBind();
}
当我单击删除时,它会更新数据库,但不会从 GV 中删除该行。我需要刷新页面或单击两次以删除该行。如何一键完成?