Solved

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

Posted on 2007-03-19
2
4,154 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

726 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