Why can I not get this code to work in My Gridview

52 Views Asked by At

I am using a Telerix RadGrid and cannot seem to get the code to provide the value of a checkbox. This is my C# code

protected void gvMembers_UpdateCommand(object sender, GridCommandEventArgs e)
    {
        var editableItem = ((GridEditableItem)e.Item);
        var memberId = (int)editableItem.GetDataKeyValue("UserID");
        int Role = 1;
        CheckBox active = (CheckBox)editableItem["valid"].Controls[0];
        Boolean boolactive = Convert.ToBoolean(active.Checked = !String.IsNullOrEmpty(e.Item.Cells[0].Text));
        string strFirstName = (editableItem["firstname"].Controls[0] as TextBox).Text;
        string strLastName = (editableItem["lastname"].Controls[0] as TextBox).Text;
        string strUserName = (editableItem["username"].Controls[0] as TextBox).Text;
        string strEmail = (editableItem["firstname"].Controls[0] as TextBox).Text;

The code compiles and runs but the checkbox value is always false. What am I missing?

I have done some more troubleshooting and have discovered this code:

CheckBox active = (CheckBox)editableItem["valid"].Controls[0];

returns this value {Text = "" Checked = true}

I then added this as my next line of code:

 string str = active.Text;

and inspected the value of the string it Returns an empty string.

Any Ideas on how I can get the boolean value from the checkbox so I can pass it to the database?

1

There are 1 best solutions below

0
On

I was able to solve the problem by using the following to get the Boolean value:

            CheckBox active = (CheckBox)editableItem["valid"].Controls[0];
        Boolean bactive = active.Checked;

Thanks for your comments.