第一次用到 (object sender)
<asp:CheckBox ID="cbActive" runat="server" AutoPostBack="true" ForeColor="blue"
Checked='<%# DataBinder.Eval(Container.DataItem, "IsApproved") %>'
ToolTip='<%# DataBinder.Eval(Container.DataItem, "UserName") %>'
OnCheckedChanged="CheckBox_Click"/>
protected void CheckBox_Click(object sender, EventArgs e)
{
try
{
CheckBox cbIsApproved = (CheckBox)sender;
string username = cbIsApproved.ToolTip;
MembershipUser mu = Membership.GetUser(username);
mu.IsApproved = cbIsApproved.Checked;
Membership.UpdateUser(mu);
gvUsers.DataSource = Membership.GetAllUsers();
gvUsers.DataBind();
lbMessage.Text = "更新成功。";
}
catch (System.Configuration.Provider.ProviderException ex)
{
lbMessage.Text = ex.Message;
}
}