使用会员 ASP:NET 检查复选框

发布于 2024-09-26 22:57:59 字数 1457 浏览 3 评论 0原文

我有一个 GirdView 使用 ASP:NET 成员身份监听系统中所有活动的用户。 我想要一个可以选择或不选择的复选框,具体取决于特定用户是否已批准。 使用事件处理程序 RowDataBound,我的脚本不起作用。 知道在适当的情况下选择复选框吗?

感谢您的宝贵时间:-)

        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;
        }
    }

I have a GirdView listening all Users active in my system using ASP:NET Membership.
I would like have a CheckBox that could be SELECTED or NOT depending if a specific user is APPROVED or not.
With event handler RowDataBound, my script does not work.
Any idea to selected the CheckBox in the appropirate case?

Thanks for your time :-)

        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;
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

海的爱人是光 2024-10-03 22:58:01
MembershipUser myUser = (MembershipUser)e.Row.DataItem;
CheckBox activeCheckBox = (CheckBox)e.Row.FindControl("uxActiveCheckBoxSelector");
activeCheckBox.Checked = myUser.IsApproved;

希望这有帮助

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

Hope this helps

回眸一笑 2024-10-03 22:58:01

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

HTH。

You have to change the myUser variable to a MembershipUser reference; by default, Object doesn't have the property defined...

HTH.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文