Solved

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

Posted on 2007-03-19
2
4,136 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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 don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

757 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

23 Experts available now in Live!

Get 1:1 Help Now