Are you sure the column being returned is a bit?

I did a little test using your item template and the following code:

        DataTable dt = new DataTable();
        dt.Columns.Add("Active", typeof(bool));
        byte b = 0;
        DataRow dr = dt.NewRow();
        dr["Active"] = b;
        dt.Rows.Add(dr);
        DataGrid1.DataSource = dt;
        DataGrid1.DataBind();

.NET handled the conversion of the byte to boolean without a problem
and the checkbox was checked or unchecked properly based on the
setting of b.

So I figured I try it against a live datatable pulled from the
database that had a bit column.

DataTable dt = new DataTable();

SqlConnection conn = new
SqlConnection(ConfigurationSettings.AppSettings["connString"]);
SqlCommand cmd = new SqlCommand("SELECT * FROM
ADDRESSES",conn);SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);

DataGrid1.DataSource = dt;
DataGrid1.DataBind();

And that worked too. So my bet is that the type in the column is not a bit.



On 11/9/05, Jim Brinkman <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
>
>
> I am trying to build a datagrid dynamically and adding columns by looping 
> through a recordset of column names. One of the columns is a bit in SQL 
> server and I know you can have a checkbox display as checked based on the bit 
> value if you are doing a straight forward dataset bind. But my problem is, 
> What "typeof" column do I need to be adding to my datatable for this "bit" 
> column so that the checkbox reads the value correctly? Here's the error I am 
> getting:
>
>
>
> System.FormatException: String was not recognized as a valid Boolean. at 
> System.Boolean.Parse(String value) at System.Convert.ToBoolean(String value, 
> IFormatProvider provider) at 
> System.String.System.IConvertible.ToBoolean(IFormatProvider provider) at 
> System.Convert.ToBoolean(Object value) at 
> System.Data.Common.BooleanStorage.Set(Int32 record, Object value) at 
> System.Data.DataColumn.set_Item(Int32 record, Object value)Couldn't store <1> 
> in Active Column. Expected type is Boolean.
>
>
>
>
>
> Here's my column add statement:
>
> //Value of Header is "Active"
>
> dataTable.Columns.Add(dataRowColumn["Header"].ToString(), typeof(bool));
>
>
>
> Here's my datagrid item template:
>
>   <ItemTemplate>
>     <asp:CheckBox ID="Checkbox1" runat="server" 
> Checked='<%#DataBinder.Eval(Container.DataItem, "Active")%>'></asp:CheckBox>
>   </ItemTemplate>
>
>
>
> Thanks,
>
> Jim
>
>
>
> ---------------------------------
>  Yahoo! FareChase - Search multiple travel sites in one click.
>
> [Non-text portions of this message have been removed]
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>


--
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Fair play? Video games influencing politics. Click and talk back!
http://us.click.yahoo.com/T8sf5C/tzNLAA/TtwFAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to