473,394 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Set checkbox in datagrid manually/through code

I have a numeric Oracle field which stores -1 for true and 0 for
false. I am trying to populate a checkbox in a datagrid. In my SQL
statement, I used the Decode function so that when it populates the
dataset that I would store the string 'true' and 'false' rather than a
numeric value. I did this because I thought it would make it easier
to actually set the value in the checkbox. Anyway, I bind the dataset
to the datagrid. In my HTML code, the checkbox is contained in a
templatecolumn:

<asp:CheckBox id="chkStrainerFuelLine" runat="server" Checked='<%#
(bool) DataBinder.Eval(Container.DataItem,
"strainer_on_fuel_line_bool") %>' Enabled="False"></asp:CheckBox>

However, this will not work. It complains that "Specified cast is not
valid."

I have even tried it without the "(bool)" cast and it still didn't
work.

The data in my database has the value stored as either a -1 or 0. In
either case, I just want to set the check box to checked or unchecked.
I was even wondering if I needed to use one of the d atagrid's events
to do this.

Any ideas or help is appreciated.

Thanks,
Marty
Nov 18 '05 #1
2 2049
Some suggestions

Try using a helper function to interpret your -1 or 0 instead of adjusting your recordset to return true or false

In your codebehind

protected bool GetCheckBoxSetting(object myObj

int myInt = Convert.ToInt16(myObj)
return (myInt == -1)
Then in your aspx

<asp:CheckBox id="chkStrainerFuelLine" runat="server" Checked='<%
GetCheckBoxSetting(DataBinder.Eval(Container.DataI tem, "strainer_on_fuel_line_bool")) %>' Enabled="False"></asp:CheckBox

If returning bool doesn't set the checkbox checked property correctly then try returning a string from GetCheckBoxSetting method

protected string GetCheckBoxSetting(object myObj

int myInt = Convert.ToInt16(myObj)
if (myInt == -1
return "true"
els
return "false"
HTH
Suresh

----- Marty wrote: ----

I have a numeric Oracle field which stores -1 for true and 0 fo
false. I am trying to populate a checkbox in a datagrid. In my SQ
statement, I used the Decode function so that when it populates th
dataset that I would store the string 'true' and 'false' rather than
numeric value. I did this because I thought it would make it easie
to actually set the value in the checkbox. Anyway, I bind the datase
to the datagrid. In my HTML code, the checkbox is contained in
templatecolumn

<asp:CheckBox id="chkStrainerFuelLine" runat="server" Checked='<%
(bool) DataBinder.Eval(Container.DataItem
"strainer_on_fuel_line_bool") %>' Enabled="False"></asp:CheckBox

However, this will not work. It complains that "Specified cast is no
valid.

I have even tried it without the "(bool)" cast and it still didn'
work

The data in my database has the value stored as either a -1 or 0. I
either case, I just want to set the check box to checked or unchecked
I was even wondering if I needed to use one of the d atagrid's event
to do this

Any ideas or help is appreciated

Thanks,
Mart

Nov 18 '05 #2
It worked, thanks!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Randy | last post by:
Hello, I'm creating a table on the fly that is used by a datagrid. I'm also creating a tableStyle that is used for the datagrid to make it look like I want. I'm using the DataGridBoolColumn to...
0
by: microsoft.public.dotnet.languages.csharp | last post by:
I have a numeric Oracle field which stores -1 for true and 0 for false. I am trying to populate a checkbox in a datagrid. In my SQL statement, I used the Decode function so that when it populates...
0
by: mike | last post by:
Hi there: I've read an excellent "how to"-article by Microsoft (no. 306227) - partly cited cited at the end of this email). I have implemented the code related to the part "How to Add a...
1
by: Machi | last post by:
Let say i select rows of records with 4 columns from Database and want to display the data in DataGrid (ASP.NEt Server Control) with one column which must be displayed in CheckBox layout. For the...
10
by: Jennyfer J Barco | last post by:
Hello, I have a datagrid that brings some information from a query. I need to have a checkbox in each row so the user can select the rows he wants to reprint. Is it possible to have a checkbox...
3
by: Mark | last post by:
Hi everyone, could someone please recommend a way to do the following. I have a datagrid which contains a bound template column consisting of checkbox and a string pulled from a database table....
2
by: wrytat | last post by:
I have a datagrid that has a column of checkbox in every row. And also 2 columns of 2 forms, each form with a textarea and a submit button. I have a button below the datagrid. And I place a form...
2
by: Ceema M via DotNetMonster.com | last post by:
Hello all, I have a nested repeater, which displays categories(parent repeater) and corresponding subcategories(child repeater). Both repeaters have checkboxes. When I check category checkbox...
4
by: mamun | last post by:
Hi All, I have the following situation and am looking for answer in C#. I have a datagrid and putting checkbox next to each record. In the header I have a Delete button. I want users to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.