I have a Telerick Radgrid that contains a GridCheckBoxColumn in the MasterTable View:
<telerik:GridCheckBoxColumn DataField="Valid" HeaderText="Active" SortExpression="Valid" UniqueName="valid"></telerik:GridCheckBoxColumn>
I want to update a record 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 bactive = Convert.ToBoolean(active);
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 am using a stored procedure to do the update and I need to convert the value of the checkbox column to a boolean. I have tried doing a conversion but it does not work. I get an error message:
System.InvalidCastException was unhandled by user code
HResult=-2147467262
Message=Unable to cast object of type 'System.Web.UI.WebControls.CheckBox' to type 'System.IConvertible'.
Source=mscorlib
StackTrace:
at System.Convert.ToBoolean(Object value)
at HomLog2015.TelerixCRUDTemplate.gvMembers_UpdateCommand(Object sender, GridCommandEventArgs e) in D:\Visual Studio 2013\Projects\Active UnderConstruction\HomLog2015\HomLog2015\TelerixCRUDTemplate.aspx.cs:line 137
at Telerik.Web.UI.RadGrid.OnUpdateCommand(GridCommandEventArgs e)
at Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source)
at Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
at Telerik.Web.UI.GridEditFormItem.OnBubbleEvent(Object source, EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
at System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
When I set a watch on active I see this as it's value {Text = "" Checked = true}
Anyone have an idea how I can make this conversion?