Solved

Binding checkbox in GridView to a "Y" or "N" char(1) field in database table.

Posted on 2007-03-19
2
4,145 Views
Last Modified: 2013-11-07
Is there a simple way to have a checkbox in a GridView bound to a column in the database table that is a CHAR(1) column with a value of "Y" or "N"? I have the GridView bound to an SqlDataSource control, but if I need to bind the GridView to a DataSet created in the code-behind, I could do that, too. The data is coming from a Stored Procedure, so I could also modify the proc to return a boolean instead of the Y/N, but I also need to do an "add" and "update" through the GridView, and so that would also mean modifying those procs to translate the boolean value from the GridView into the Y/N needed by the database table.

Any of these would be simple enough to accomplish, but I'm just wondering about how to go about binding a checkbox to a CHAR(1) column.
0
Comment
Question by:DanielBorson
2 Comments
 
LVL 22

Accepted Solution

by:
DarkoLord earned 125 total points
ID: 18750429
You can use helper function to accomplish this:

C# example:

<asp:CheckBox ID="CheckBox1" Checked='<%# ((string)Eval("FieldInDatabase") == "s") %>' runat="server" />

0
 

Author Comment

by:DanielBorson
ID: 18751077
Thanks. That did the trick.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Jquery autocomplete 10 68
consuming an asmx web service in winforms application 3 24
SQL Exceptions 3 38
C# MVC and a global static factory that never dies 4 47
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now