CheckBoxField returning string?

A

absentia.no

I am using a datagrid and have a column which should consist of
checkboxes. The datafield that generates the checkbox-column is bit,
but I am getting this format error:
System.FormatException: String was not recognized as a valid Boolean.

If I use boundField instead everything works fine, but I want to use
the checkboxes as it seems very odd to make my users type in 0 or 1
manually to decide wether to turn off or on.

Also, I have made a custom update method which uses bool as the input
for the checkbox-variable.

What am I doing wrong?
royend.
 
M

MasterGaurav \(www.edujini-labs.com\)

I am using a datagrid and have a column which should consist of
checkboxes. The datafield that generates the checkbox-column is bit,
but I am getting this format error:
System.FormatException: String was not recognized as a valid Boolean.

CheckboxColumn? Never heard of it!
It seems you are using AutoGenerateColumns=true! If so, it would work
without any problems.
If I use boundField instead everything works fine, but I want to use
the checkboxes as it seems very odd to make my users type in 0 or 1
manually to decide wether to turn off or on.

Make it a TemplateColumn with:

<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "FieldName") %>
</ItemTemplate>
<EditItemTemplate>
<asp:Checkbox runat='server' id='fieldBox' Selected='<%#
DataBinder.Eval(Container.DataItem, "FieldName") == "0" ? "false : "true"'
/>
</EditItemTemplate>

And on the server side:

dataGrid1_UpdateCommand(sender, e)
{
DataGridItem row = e.Item;
Checkbox box = (Checkbox) row.FindControl("fieldBox");
bool selected = box.Selected;
int value = selected ? 1 : 0;

//... and proceed.
}

HTH
Also, I have made a custom update method which uses bool as the input
for the checkbox-variable.

Can you elaborate? A piece of code from you may help analyze the problem
better.



--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top