473,386 Members | 1,708 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,386 software developers and data experts.

Set checkbox value based on data grid string value

Using Visual Studio 2003, C#, .NET 1.1.

I have a web form with a few textboxes, a couple of dropdown lists, and a
data grid. The data grid is populated from a SQL stored procedure. The user
can select a row to edit by clicking an EDIT link, which triggers an Edit
command. The textboxes and dropdowns are then populated with the data from
the data grid.

I've added a new column to the data grid and a checkbox control. The column
is populated with either "YES" or "NO" based on whether the SQL field value
is 1 or 0 (integer field). This works just fine. The new column is column 8.

What I'm struggling with is having the checkbox be checked if the data grid
value is "YES" and clear if the value is "NO." Here's what I tried:

if (e.Item.Cells[8].Text.Trim(); == "YES") chkAlerts.Checked = true;
else chkAlerts.Checked = false;

I also tried:

string Cell8 = e.Item.Cells[8].Text.Trim();
if( Cell8 == "YES") chkAlerts.Checked = true;
else chkAlerts.Checked = false;

Am I on the right track? If not, can someone please help me out?

Thanks!
Oct 12 '06 #1
1 5194
may be you can add one more column in query, like that

select Convert(bit, 1) as COL8
....or
select (CASE WHEN Convert(bit, 1) = 1 THEN 'YES' ELSE 'No' end) as Col8
....or
select (CASE WHEN var = 'YES' THEN 1 ELSE 0 end) as Col8

Oct 13 '06 #2

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

Similar topics

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: Chip | last post by:
I'm using Andy Smith's RowSelectorColumn control (great control) and I'm not sure if this question is generic to all datagrid controls or this particular one. Is there a way to disable one of...
2
by: Asha | last post by:
greetings, i'm loading a datagrid and my gird has checkbox, i want these checkboxex to be check based on the value from the db? can someone please show me the code for it? thanks
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...
1
by: mercercreek | last post by:
This one should be easy. Hope someone has a clue. Simple Scenario: Gridview with mulitple rows, each row with a checkbox. The user checks boxes of her choice. Clicks a button on the form (not in...
9
by: mike7510uk | last post by:
Hi, I am using a gridview with a templatefield containing a checkbox. I want to update the database with a 1 or 0 depending on if a checkbox is checked or unchecked (then use the 1 or 0 later on...
1
by: mamun | last post by:
Hi All, I have the following situation. In the aspx page, I have a datagrid and getting values from the database. I am displaying checkbox in each row of the grid. At the top of the grid I...
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...
3
by: =?Utf-8?B?Um9iZXJ0IFNtaXRo?= | last post by:
Hi, I have a GridView with a checkbox column in it called FromInsight, however this is not bound to the dataset, its value is based on another column from the dataset called sourceid For each...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.