Format how a field is displayed in grid

P

Poppy

In my code behind I add a coloumn to a datgrid :

Code:
lBlockUsedUp.DataField = "BlockUsedUp"
Code:
lBlockUsedUp.HeaderText = "Blocks Used Up"
Code:
lBlockUsedUp.ItemStyle.Width = New Unit(300)
Code:
 dgBiopsyLocation.Columns.Add(lBlockUsedUp)

I then bind in code with :

Code:
 dgBiopsyLocation.DataSource = iDataset.Tables
("ArrBiopsyLocation")
Code:
dgBiopsyLocation.DataBind()

The problem I am having is that the field "BlockUsedUp",
which is a bit field in SQL SERVER always shows "FALSE"
when the value = 0. I want this to be "" if it is 0 and I
want to do it all in my code behind.

Can anyone help ?
 
M

mortb

If it is an option you can try to do this in the SQL statement

Something like:

SELECT
col1,
CASE col2
WHEN 1 THEN 'True'
ELSE ''
END AS newCol2
FROM
myTable

/mortb
 
J

John Saunders

Poppy said:
In my code behind I add a coloumn to a datgrid :

Code:
lBlockUsedUp.DataField = "BlockUsedUp"
Code:
lBlockUsedUp.HeaderText = "Blocks Used Up"
Code:
lBlockUsedUp.ItemStyle.Width = New Unit(300)
Code:
 dgBiopsyLocation.Columns.Add(lBlockUsedUp)

I then bind in code with :

Code:
 dgBiopsyLocation.DataSource = iDataset.Tables
("ArrBiopsyLocation")
Code:
dgBiopsyLocation.DataBind()

The problem I am having is that the field "BlockUsedUp",
which is a bit field in SQL SERVER always shows "FALSE"
when the value = 0. I want this to be "" if it is 0 and I
want to do it all in my code behind.

Can anyone help ?

What kind of column is it? A BoundColumn? You may need to use a
TemplateColumn.

bit(1) in SQL is translated to bool in .NET.
 

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

Members online

No members online now.

Forum statistics

Threads
474,142
Messages
2,570,819
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top