BoundColumn Formatting question

Discussion in 'ASP .Net' started by Andrea Williams, May 6, 2004.

  1. 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
     
    Andrea Williams, May 6, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
    >
    >
    >
     
    microsoft.public.dotnet.framework.aspnet.webcontro, May 6, 2004
    #2
    1. Advertising

  3. Andrea Williams

    Jim Corey Guest

    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!
     
    Jim Corey, May 6, 2004
    #3
  4. 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/issues/02/01/cutting/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" <> wrote in message
    news:...
    > 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
    >
    >
     
    Andrea Williams, May 7, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. May
    Replies:
    0
    Views:
    379
  2. Volodymyr Lozovoy
    Replies:
    7
    Views:
    4,517
    Volodymyr Lozovoy
    Dec 9, 2004
  3. Replies:
    1
    Views:
    499
    Teemu Keiski
    Jun 22, 2005
  4. =?Utf-8?B?Q2hhcmxlc0E=?=

    boundcolumn formatting question

    =?Utf-8?B?Q2hhcmxlc0E=?=, Feb 2, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    401
    =?Utf-8?B?Q2hhcmxlc0E=?=
    Feb 2, 2006
  5. mesut
    Replies:
    0
    Views:
    578
    mesut
    Jun 29, 2007
Loading...

Share This Page