DropDownList and DataSet. Where is my error?

Discussion in 'ASP .Net' started by Emanuele, Jul 20, 2007.

  1. Emanuele

    Emanuele Guest

    Hi People, I want populate one DropDownList with a DataSet.
    I've got one problem when I pass the data and text value. My code
    (propabily wrong)
    pass always the first value of my droplist.

    DataSet dst = new DataSet();


    dst = myobject.GetDataSet();


    droplist.DataSource = dst.Tables[0];
    droplist.DataTextField =
    dst.Tables[0].Columns["TextValueColumn"].ToString();
    droplist.DataValueField =
    dst.Tables[0].Columns["DataValueColumn"].ToString();
    droplist.DataBind();

    ***************************
    this.Label1.Text = droplist.SelectedItem.Text;
    this.Label2.Text = droplist.SelectedItem.Value;

    Can you help me?

    (sorry for my english, but I'm italian....!)
     
    Emanuele, Jul 20, 2007
    #1
    1. Advertising

  2. Emanuele

    Emanuele Guest

    On 20 Lug, 15:20, Emanuele <> wrote:
    > Hi People, I want populate one DropDownList with a DataSet.
    > I've got one problem when I pass the data and text value. My code
    > (propabily wrong)
    > pass always the first value of my droplist.
    >
    > DataSet dst = new DataSet();
    >
    > dst = myobject.GetDataSet();
    >
    > droplist.DataSource = dst.Tables[0];
    > droplist.DataTextField =
    > dst.Tables[0].Columns["TextValueColumn"].ToString();
    > droplist.DataValueField =
    > dst.Tables[0].Columns["DataValueColumn"].ToString();
    > droplist.DataBind();
    >
    > ***************************
    > this.Label1.Text = droplist.SelectedItem.Text;
    > this.Label2.Text = droplist.SelectedItem.Value;
    >
    > Can you help me?
    >
    > (sorry for my english, but I'm italian....!)


    Nobody can help me?
     
    Emanuele, Jul 20, 2007
    #2
    1. Advertising

  3. Emanuele

    David Wier Guest

    Don't worry - I wish I could speak Italian half as good as you speak English
    are you having troubles setting the DataTextField/DataValueField, before
    binding, or in the label part you had below it?

    --
    David Wier
    MVP/ASPInsider
    http://aspnet101.com
    http://iWritePro.com



    "Emanuele" <> wrote in message
    news:...
    > Hi People, I want populate one DropDownList with a DataSet.
    > I've got one problem when I pass the data and text value. My code
    > (propabily wrong)
    > pass always the first value of my droplist.
    >
    > DataSet dst = new DataSet();
    >
    >
    > dst = myobject.GetDataSet();
    >
    >
    > droplist.DataSource = dst.Tables[0];
    > droplist.DataTextField =
    > dst.Tables[0].Columns["TextValueColumn"].ToString();
    > droplist.DataValueField =
    > dst.Tables[0].Columns["DataValueColumn"].ToString();
    > droplist.DataBind();
    >
    > ***************************
    > this.Label1.Text = droplist.SelectedItem.Text;
    > this.Label2.Text = droplist.SelectedItem.Value;
    >
    > Can you help me?
    >
    > (sorry for my english, but I'm italian....!)
    >
     
    David Wier, Jul 20, 2007
    #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. Nedu N
    Replies:
    1
    Views:
    1,800
    Chris Taylor
    Oct 31, 2003
  2. JimO

    DataSet and dataSet

    JimO, Mar 1, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    523
    Mary Chipman [MSFT]
    Mar 8, 2006
  3. thomson
    Replies:
    2
    Views:
    14,833
    Eliyahu Goldin
    Jan 19, 2005
  4. ringo
    Replies:
    0
    Views:
    173
    ringo
    Aug 18, 2004
  5. wrecker
    Replies:
    1
    Views:
    179
    Wardeaux
    Feb 13, 2004
Loading...

Share This Page