I am using a gridview that has a check box. I am trying to update the record in the database using this 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 runs but the value of the checkbox is always false. What am I doing wrong here?
I have done some more troubleshooting and have added another line of code. Code is now this:
var editableItem = ((GridEditableItem)e.Item);
var memberId = (int)editableItem.GetDataKeyValue("UserID");
int Role = 1;
CheckBox active = (CheckBox)editableItem["valid"].Controls[0];
string str = active.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;
I added a string to get the text value of the checkbox. When I inspect the value of string str it is an empty string. When I inspect the value of the checkbox I am seeing this value: {Text = "" Checked = true} How can I get
that checked = true value as boolean