views:

20

answers:

2

Hi, 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;
        }
    }
+1  A: 
MembershipUser myUser = (MembershipUser)e.Row.DataItem;
CheckBox activeCheckBox = (CheckBox)e.Row.FindControl("uxActiveCheckBoxSelector");
activeCheckBox.Checked = myUser.IsApproved;

Hope this helps

Mouhannad
Thanks now I understand and it is working. I will reedit my code with the right one. I hope can help other beginners as me :-)
GIbboK
I'm glad it's been helpful but I dont know if it's a good idea to edit your question, because others now won't see anything wrong in your code. Leave the old code or just add the new code under the old message instead
Mouhannad
you are right I had not thing about it, unfortunately I do not have the old version anymore
GIbboK
A: 

Hey,

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

HTH.

Brian