首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Membership检查CheckBox

使用Membership检查CheckBox
EN

Stack Overflow用户
提问于 2010-10-13 20:52:01
回答 2查看 215关注 0票数 0

我有一个GirdView监听我的系统中使用ASP:NET成员资格的所有活跃用户。我想有一个CheckBox,可以选择或不取决于是否一个特定的用户是批准或没有。使用事件处理程序RowDataBound时,我的脚本无法工作。在合适的案例中选择CheckBox有什么想法吗?

感谢您的宝贵时间:-)

代码语言:javascript
复制
        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;
        }
    }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-10-13 21:00:11

代码语言:javascript
复制
MembershipUser myUser = (MembershipUser)e.Row.DataItem;
CheckBox activeCheckBox = (CheckBox)e.Row.FindControl("uxActiveCheckBoxSelector");
activeCheckBox.Checked = myUser.IsApproved;

希望这能有所帮助

票数 1
EN

Stack Overflow用户

发布于 2010-10-13 21:00:14

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

HTH。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3923814

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档