Skip to content

Splitting values in a combobox

Daniel Golan

Asked Jan 29, 2011, 10:35 PM ESTSolved
Share
LinkedInX
Hello,

How can i split items in a combobox ?

using the code to populate the combo and wondering how i could modify the code to split the added item at "T" since i only need the first part of the attribute :
 private void populateCombo_dato()
        {
            cmb_dato.Items.Clear();
            //åpner xml
            XDocument xmlDoc = XDocument.Load(lab_url.Text);
            //leser attributt fra bestemt setd
            var xmlAtt = from att in xmlDoc.Elements("weatherdata").Elements("forecast").Elements("tabular").Elements("time").Attributes("from")
                         select att;
            //loop og legg de i listen om de ikke finnes
            foreach (var record in xmlAtt)
            {

                if (!cmb_dato.Items.Contains(record.Value)) ;
                cmb_dato.Items.Add(record.Value);
                }
        }

5 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Suthish Nair
    ✓ Accepted answer0
    sorry for that..just convert to datetime..
    Code
     Response.Write(Convert.ToDateTime("2010-12-18T12:00:00").ToString("dd-MMMM-yyyy"));
     Response.Write("<BR />");
     Response.Write(Convert.ToDateTime("2010-12-18T12:00:00").ToString("dd-MM-yyyy"));
    0
  • 0
    "2010-12-18T12:00:00" is the data now added to the combo box but what i actually want as result would be something like 18 December or 18-12-2010 know thats abit more but if its complicated i just need help to split the to" 2010-12-18" and removing the "T12:00:00" part.
    0
  • Suthish Nair
    0
    do a replace then convert to datetime to specific format.
    Code
    Response.Write("2010-12-18T12:00:00".Replace("T", " "));
    0
  • 0
    I there any way i can implent the .Replace in the code ive writter or should it be a new function ?
    0
  • Suthish Nair
    0
    If this query got resolved then please Accept the post that helped you as Answer.

    So other members can easily find the answers.
    0
  • 1 short reply
    • Suthish Nair
      0
      Howz your data looks like?
      0