Binding to a dropdown in C#

Discussion in 'ASP .Net' started by Carlos, Dec 24, 2006.

  1. Carlos

    Carlos Guest

    Hi all,

    I have the following issue:.

    I've got datatable that I am intending to bind to a dropdownlist. While
    debugging

    I am certain that my DataTable contains 3 valid rows. However, after the
    binding

    statement ends, I have three row that read 'System.Data.DataRowView' instead
    of the

    actual data.

    Can someone help? I used to do this in VB .Net no problems referencing the
    items within

    a row, but the same can not be done in C#.

    Thanks in advance,



    Carlos.



    DataTable m_DataTable_GetSchools = CatalogAccess.GetSchools();


    DDL_SugMainMon.DataSource = m_DataTable_GetSchools;

    DDL_SugMainMon.DataBind();
    Carlos, Dec 24, 2006
    #1
    1. Advertising

  2. Carlos

    David Wier Guest

    It's because you have not assigned the field names to be shown. You most
    likely have run the databind on the DDL, but not assigned a field to the
    DDL's DataTextField. You must do at least that, and then, if you'd like,
    also assign a field to the DataValueField of the DDL

    David Wier
    MVP/ASPInsider
    http://aspnet101.com
    http://aspexpress.com

    "Carlos" <> wrote in message
    news:%...
    > Hi all,
    >
    > I have the following issue:.
    >
    > I've got datatable that I am intending to bind to a dropdownlist. While
    > debugging
    >
    > I am certain that my DataTable contains 3 valid rows. However, after the
    > binding
    >
    > statement ends, I have three row that read 'System.Data.DataRowView'
    > instead of the
    >
    > actual data.
    >
    > Can someone help? I used to do this in VB .Net no problems referencing the
    > items within
    >
    > a row, but the same can not be done in C#.
    >
    > Thanks in advance,
    >
    >
    >
    > Carlos.
    >
    >
    >
    > DataTable m_DataTable_GetSchools = CatalogAccess.GetSchools();
    >
    >
    > DDL_SugMainMon.DataSource = m_DataTable_GetSchools;
    >
    > DDL_SugMainMon.DataBind();
    >
    >
    David Wier, Dec 24, 2006
    #2
    1. Advertising

  3. Carlos

    Mark Rae Guest

    "Carlos" <> wrote in message
    news:%...

    DataTable m_DataTable_GetSchools = CatalogAccess.GetSchools();
    DDL_SugMainMon.DataSource = m_DataTable_GetSchools;
    DDL_SugMainMon.DataValueField = ""; // field from DataTable
    DDL_SugMainMon.DataTextField = ""; // field from DataTable
    DDL_SugMainMon.DataBind();
    Mark Rae, Dec 25, 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. vishnu
    Replies:
    1
    Views:
    1,191
    Patrick.O.Ige
    Mar 25, 2006
  2. Mike
    Replies:
    1
    Views:
    796
  3. acadam
    Replies:
    0
    Views:
    748
    acadam
    Dec 27, 2006
  4. Replies:
    2
    Views:
    430
  5. Steve Myers
    Replies:
    2
    Views:
    266
    Steve Myers
    Nov 20, 2003
Loading...

Share This Page