Solved

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

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

773 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