Specified Cast is Invalid – Telerik RadGrid asp:CheckBox
Jun0
Great solution to the “specified cast is invalid” problem while binding an asp.net CheckBox control inside of an Telerik RadGrid FormTemplate.
ASP.NET Classic Controls – Grid Forum – asp:Checkbox in FormTemplate. “Specified Cast is Invalid” .
From Fabian Schulz:
I ran across the same problem and have created a simple solution, which is most easy to use:
Create a usercontrol with the following code:
myCheckbox.ascx:
myCheckbox.ascx.cs:
public partial class Controls_myCheckBox : System.Web.UI.UserControl
{
private bool m_checked = false;
public object Checked
{
get { return m_checked; }
set
{
if (value.GetType() == DBNull.Value.GetType())
m_checked = false;
else if (value == null)
m_checked = false;
else if (value.GetType() == typeof(bool))
m_checked = (bool)value;
else
m_checked = false;
}
}
protected void Page_Load(object sender, EventArgs e)
{
m_checked = CheckBox1.Checked;
}
protected void Page_PreRender()
{
CheckBox1.Checked = m_checked;
}
}
In your aspx page you need to register that control in the head:
And now – you can use it like a regular checkbox without the Null problem:
Hope this helps!
Fabian
American Airlines Discount Codes
Mar0
Thanks to the power of google, we have american airlines discount codes!
Click this link for the search results: discount codes.
Google to the rescue
Jan0
Google’s teamed up with some other folks (New America Foundation’s Open Technology Institute, the PlanetLab Consortium, and academic researchers) to make available some tools to test your internet connection. This is great because when I pay for an internet connection I want the whole thing! Making these tools is ammunition for customers to fight back about ISPs filtering their connection.
Official Google Blog: Introducing Measurement Lab.
The tools: M-Lab
