使用Membership ASP:NET检查CheckBox

时间:2010-10-13 12:52:01

标签: c# asp.net asp.net-membership

我有一个GirdView使用ASP:NET Membership监听我系统中活动的所有用户。 我希望有一个可以选择或不选择的CheckBox,具体取决于特定用户是否被批准。 使用事件处理程序RowDataBound,我的脚本不起作用。 有没有想过在适当的情况下选择CheckBox?

感谢您的时间: - )

        protected void uxUserListDisplayer_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        // Check or Uncheck a CheckBox depending if user is Approved
        switch (e.Row.RowType)
        {
            // In case type of row is DataRow (a data row of GridView) 
            case DataControlRowType.DataRow:
                // Create an object of type MembershipUser for row bounded (Users)
                MembershipUser myUser = (MembershipUser)e.Row.DataItem;
                // Find out the edit button "uxLinkEditButton" and create an object for it
                LinkButton editButton = (LinkButton)e.Row.FindControl("uxLinkEditButton");
                // Find out the checkbox "uxActiveCheckBoxSelector" and create an object for it
                CheckBox activeCheckBox = (CheckBox)e.Row.FindControl("uxActiveCheckBoxSelector");
                // Check if the Object type MembershipUser for a User is approved or not
                if (myUser.IsApproved == true)
                {
                    activeCheckBox.Checked = true; // Checkbox is checked
                }
                else
                {
                    activeCheckBox.Checked = false; // Checkbox is unchecked
                }
                break;
        }
    }

2 个答案:

答案 0 :(得分:1)

MembershipUser myUser = (MembershipUser)e.Row.DataItem;
CheckBox activeCheckBox = (CheckBox)e.Row.FindControl("uxActiveCheckBoxSelector");
activeCheckBox.Checked = myUser.IsApproved;

希望这有帮助

答案 1 :(得分:0)

您必须将myUser变量更改为MembershipUser引用;默认情况下,Object没有定义属性...

HTH。