Last post May 30, 2007 10:00 PM by Tohid
Jul 19, 2006 02:53 AM|tim99|LINK
Jul 19, 2006 07:01 AM|alvinz_c|LINK
Try convert the object to boolean,
<asp:CheckBox ID="schoolCheckBox" runat="server" Checked ='<%#
Convert.ToBoolean(Bind("school")) %>' />
Hope this works...
Jul 27, 2006 02:33 PM|hapax_legomenon|LINK
I was having the same "Specified cast is not valid" problem, so I changed my code, as recommended, to:
<asp:CheckBox ID="EducationalCheckBox" runat="server"
Checked='<%# Convert.ToBoolean(Bind("Educational")) %>'
But now I get this new error:
"The name 'Bind' does not exist in the current context"
Can someone help me?
Jul 27, 2006 03:24 PM|James Alexander|LINK
Methods such as Bind() , Eval(), and XPath() only work within the context of DataBinding. These methods when executed expect that they are inside of a databinding context.
To make this work, the simplest thing to do would be to drop something like a SqlDataSource into your page, set the DataSourceID property of your FormView control containing the CheckBox control to the value you assigned the ID property of the SqlDataSource
instance, and then use the syntax: Checked='<%# Convert.ToBoolean(Bind("Educational")) %>'
Jul 31, 2006 03:58 PM|hapax_legomenon|LINK
This control is databound already.
I was assuming that a check box would return a boolean 0 or 1, but now I've now figured out that the checkbox actually returns a string "True" or "False" so I've changed my db column to accept strings instead of booleans.
May 30, 2007 10:00 PM|Tohid|LINK
1- Use Eval instead of Bind if you just show the data. Bind is for Insert and Update purposes.
2- Be sure that the "school" field of the corresponding row is not null. You can check it in your database, in BLL, or at presenting layer. E.g. you can use <asp:Label runat="server" text='<%# Eval("school") %>' ></asp:Label>
3- Be careful about case sensitivity. Eval("school") is different from Eval("ScHoOl")!