Click here to Skip to main content
16,016,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
<?xml version="1.0" encoding="utf-8" ?>
 <Title>
   <subtitle>12,15,1,4 </subtitle>
 </Title >

This is my xml structure and i need to split the value and add in dropdownlist, but iam getting whole value in dropdownlist, kindly provide me the solution and my code is


   private void bindxml()
    {
       StreamReader str = new StreamReader(filepath);
        using (DataSet ds = new DataSet())
        {
            ds.ReadXml(filepath);
            DropDownList1.DataSource = ds;
          DropDownList1.DataTextField = "subtitle";
            DropDownList1.DataBind();
        }
        }
Posted
Comments
BillWoodruff 1-Feb-16 6:58am    
Is this Windows Forms ?
vinodh107 1-Feb-16 7:30am    
s this is winforms

1 solution

hey
doc.Load can do the trick....
C#
var codeBase = Assembly.GetExecutingAssembly().CodeBase;
            UriBuilder uri = new UriBuilder(codeBase);
            string path = Uri.UnescapeDataString(uri.Path);
            var pathname = Path.GetDirectoryName(path) + @"\test.xml";
            var doc = new XmlDocument();

            doc.Load(pathname);
            XmlNode node = doc.DocumentElement.SelectSingleNode("/Title/subtitle");
            var csv = node.InnerText;

            DataTable table = new DataTable();
            string[] valarr = csv.Split(',');

            table.Columns.Add("subtitle", typeof(string));
            for (int i = 0; i < valarr.Length; i++)
            { 
                table.Rows.Add(valarr[i]);
            }

            var a = table;
            Console.ReadKey();

                
              //DropDownList1.DataSource = ds;
              //DropDownList1.DataTextField = "subtitle";
              //DropDownList1.DataBind();

Thanks
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900