DataBinding ListBox.DataTextField

Discussion in 'ASP .Net' started by =?Utf-8?B?bXVzb3NkZXY=?=, Apr 3, 2006.

  1. Hi guys

    I have an asp:ListBox on my form, which I'm populating with a DataReader,
    using DataSource/DataBind.

    The problem is that the main field I want to use for DataTextField,
    "Company" in this case, is often blank. How can I get the DataBinding to
    go...

    "if Company is blank, use ContactName, else use Company"

    ...is that even possible? Or is there a way I can do this in the SQL somehow?

    Hope that makes sense!

    Cheers



    Dan
    =?Utf-8?B?bXVzb3NkZXY=?=, Apr 3, 2006
    #1
    1. Advertising

  2. Dan,

    You can do it in the select:

    select ... case Company when null then ContactName else Company end as
    CompanyName...

    Eliyahu

    "musosdev" <> wrote in message
    news:...
    > Hi guys
    >
    > I have an asp:ListBox on my form, which I'm populating with a DataReader,
    > using DataSource/DataBind.
    >
    > The problem is that the main field I want to use for DataTextField,
    > "Company" in this case, is often blank. How can I get the DataBinding to
    > go...
    >
    > "if Company is blank, use ContactName, else use Company"
    >
    > ..is that even possible? Or is there a way I can do this in the SQL
    > somehow?
    >
    > Hope that makes sense!
    >
    > Cheers
    >
    >
    >
    > Dan
    Eliyahu Goldin, Apr 3, 2006
    #2
    1. Advertising

  3. Hi Dan,

    ListBox is a simple databound control which doesn't support itemdatabound
    event like repeater or datalist. So if you want to do it in ASP.NET layer,
    you can consider programmtically loop through the datareader and populate
    the listbox instead of using databinding. Also, for T-SQL layer, you can
    have a look at Eliyahu's suggestion and you can also try posting in
    SQLServer. programming newsgroup since there're many experiences SQL guys
    there.

    Regards,

    Steven Cheng
    Microsoft Online Community Support


    ==================================================

    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.

    ==================================================


    This posting is provided "AS IS" with no warranties, and confers no rights.



    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    Steven Cheng[MSFT], Apr 4, 2006
    #3
    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. NBB
    Replies:
    1
    Views:
    502
  2. tshad
    Replies:
    3
    Views:
    4,574
    tshad
    May 10, 2005
  3. Nathan Sokalski

    Combining 2 Fields Using ListBox.DataTextField

    Nathan Sokalski, Nov 9, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    8,559
    Patrick.O.Ige
    Nov 10, 2005
  4. l7alabeh
    Replies:
    4
    Views:
    2,620
    l7alabeh
    Sep 20, 2006
  5. Eric Layman

    databinding - datatextfield questions

    Eric Layman, Apr 2, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    343
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
    Apr 3, 2007
Loading...

Share This Page