Specified Cast is Invalid – Telerik RadGrid asp:CheckBox

30
Jun
0

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

30
Mar
0

Thanks to the power of google, we have american airlines discount codes!

Click this link for the search results: discount codes.

Filed under: google, hacks, misc, tools

I’ve Been Tagged!

11
Feb
0

mytag

You can get your Tag here.

Google to the rescue

29
Jan
0

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

Filed under: google, tools