473,662 Members | 2,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Check ed = true;
else chkAlerts.Check ed = false;

I also tried:

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

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

Thanks!
Oct 12 '06 #1
1 5207
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
2397
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 CheckBox Programmatically" in my code. I have changed it to use a OLDDB.DBReader to populate the datagrid and for the databinding. It works perfectly - also when using the edit-mode in the datagrid.
1
1584
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 the checkboxes based on data in the grid? If so, can you provide the syntax? Thanks, Chip
2
6558
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
2425
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 control in a datagrid? Now I have a Select column but the problem is that the user needs to select more than one record and send them all to print, instead of being one by one like is now with the Select column. Another question, is it possible to...
1
21464
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 the grid). Desired aciton is then taken in response to the button_onclick event relevant to the row in which the checked checkboxes exist. Unfortunate Outcome: Each checkbox returns false for its attribute:checked whether the user has placed a...
9
5531
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 another page)..i have been google around and found this.... If e.Row.RowType = DataControlRowType.DataRow Then Dim Chk As CheckBox = e.Row.FindControl("CheckBox1") just dont know what to do next...Any ideas?
1
1944
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 have an "Update" button which will be used to update the contents based on Bore_Id field. This field in the database is Number
4
7492
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 checkchekboxes and click the Delete button. That will show a confirmation dialog message with the items they choose to delete.
3
9006
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 row FromInsight = true if (SourceId 0). I try to loop around the gridview and add the value of the checkbox but the column seems to have no checked value, please can you help with this. Thanx in advance Robert
0
8435
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8345
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8768
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7368
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5655
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1754
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.