Set checkbox value based on data grid string value

G

Guest

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

I also tried:

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

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

Thanks!
 
S

salman

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top