Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > BoundColumn Formatting question

Reply
Thread Tools

BoundColumn Formatting question

 
 
Andrea Williams
Guest
Posts: n/a
 
      05-06-2004
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


 
Reply With Quote
 
 
 
 
microsoft.public.dotnet.framework.aspnet.webcontrols
Guest
Posts: n/a
 
      05-06-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>



 
Reply With Quote
 
 
 
 
Jim Corey
Guest
Posts: n/a
 
      05-06-2004
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!
 
Reply With Quote
 
Andrea Williams
Guest
Posts: n/a
 
      05-06-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Boundcolumn or TemplateField when to use Boundcolumn and when TemplateField ???? mesut ASP .Net 0 06-29-2007 10:17 AM
boundcolumn formatting question =?Utf-8?B?Q2hhcmxlc0E=?= ASP .Net 0 02-02-2006 03:31 PM
Datagrid boundcolumn and edititemtemplate question needin4mation@gmail.com ASP .Net 1 06-22-2005 06:35 PM
ASP/DataGrid/BoundColumn/Data formatting expression fo Date? Volodymyr Lozovoy ASP .Net 7 12-09-2004 04:09 PM
convert tablecell to boundcolumn May ASP .Net 0 06-30-2003 07:43 PM



Advertisments