By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,035 Members | 1,555 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,035 IT Pros & Developers. It's quick & easy.

BoundColumn Formatting question

P: n/a
I have a BoundColumn which shows a field called 'IsPrimary'. Straight from
the database, the field is a 1 or 0 (bit). But I want to show 'Yes' or 'No'
instead. Or better yet, an image only if the value equals one.

Does anyone have some code sample of how this could be done in code-behind?

Here's my bound column code:

dgc = new BoundColumn();
dgc.HeaderText = "Primary Contact";
dgc.DataField = nvcAuthor.Get("IsPrimary");
this.dgdAuthors.Columns.Add(dgc);

I've looked at TemplateColumns in the MSDN help, but I only see samples
where a template column is used in the ASPX and I want it in the
code-behind.

Thanks in advance,
Andrea
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Two ideas:

1. Update your SQL query (if that is where it comes from) to return "Yes" or
"No" instead of 1 or 0.

2. You can make the column with 1 or 0 invisible and add another column that
is not bound. Go through your datagrid after it is loaded and insert the
image or text of your choice depending on the Text property of the invisible
field.
"Andrea Williams" <an*******@hotmail.IHATESpam.com> wrote in message
news:Ox**************@TK2MSFTNGP11.phx.gbl...
I have a BoundColumn which shows a field called 'IsPrimary'. Straight from the database, the field is a 1 or 0 (bit). But I want to show 'Yes' or 'No' instead. Or better yet, an image only if the value equals one.

Does anyone have some code sample of how this could be done in code-behind?
Here's my bound column code:

dgc = new BoundColumn();
dgc.HeaderText = "Primary Contact";
dgc.DataField = nvcAuthor.Get("IsPrimary");
this.dgdAuthors.Columns.Add(dgc);

I've looked at TemplateColumns in the MSDN help, but I only see samples
where a template column is used in the ASPX and I want it in the
code-behind.

Thanks in advance,
Andrea

Nov 18 '05 #2

P: n/a
If this is a datagrid, then you can do this sort of thing in the
itemdatabound event:

If (e.Item.ItemType = ListItemType.AlternatingItem) Or
(e.Item.ItemType = ListItemType.Item) Then
If e.Item.Cells(0).Text = "0" Then
e.Item.Cells(1).Text = "No"
End If
End If

You might want to keep your original column hidden and
have a separate column for an icon.

Jim

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3

P: n/a
Thanks for your responses :-)

But I found what I was looking for in an old issue of MSDN Magazine. I had
to take my hubby into the Dr. and brought old magazines with me to read
while I was waiting. I found an article in in the January 2002 issue in the
Cutting Edge column (page 41). It's also here, should anyone else want the
info:

http://msdn.microsoft.com/msdnmag/is...g/default.aspx

I created a class that Implemented ITemplate and created my own template for
boolean data. Works pretty well too.

Contact me directly if you'd like my template code. I don't mind sharing
it, it's pretty simple.

Andrea

"Andrea Williams" <an*******@hotmail.IHATESpam.com> wrote in message
news:Ox**************@TK2MSFTNGP11.phx.gbl...
I have a BoundColumn which shows a field called 'IsPrimary'. Straight from the database, the field is a 1 or 0 (bit). But I want to show 'Yes' or 'No' instead. Or better yet, an image only if the value equals one.

Does anyone have some code sample of how this could be done in code-behind?
Here's my bound column code:

dgc = new BoundColumn();
dgc.HeaderText = "Primary Contact";
dgc.DataField = nvcAuthor.Get("IsPrimary");
this.dgdAuthors.Columns.Add(dgc);

I've looked at TemplateColumns in the MSDN help, but I only see samples
where a template column is used in the ASPX and I want it in the
code-behind.

Thanks in advance,
Andrea

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.