开发者

single XML file but need to populate 2 dropdownlist

i have 2 dropdownlist to implement and the xml file is as follow:

    <?xml version="1.0" encoding="utf-8"?>
<email>
  <builderemail>
    <builder id="1"  value="builder@xyz.com">
    </builder>
    <builder id="2" value="Others">
    </builder>
  </builderemail>
  <manageremail>
    <manager id="1" value="manager@xyz.com"></manager>
    <manager id="2" value="Others"></manager>
  </manageremail>
</email>

i am using visual studio 2005 and i tried to data bind each drop down list by choosing a data source. my requirements are that one of the drop downlist for builder's email and the other drop down list for manager's email. How do i do that by using the datasource config开发者_运维问答uration wizard?

regards


These links might help you out

http://www.codeproject.com/KB/aspnet/xmlboundlistcontrol.aspx

http://dotnetspidor.blogspot.com/2009/04/bind-aspnet-dropdownlist-to-xml-file.html

But you might have to change your xml and structure it like

<?xml version="1.0" encoding="utf-8"?>
<email>
  <builderemail>
    <builder> 
      <id>1</id>  
      <value>builder@xyz.com</value>
    </builder>
  </builderemail>
  <manageremail>
    <manager> 
      <id>1</id>  
      <value>manager@xyz.com</value>
    </builder>
  </manageremail>
</email>

Hope this helps


You need to parse xml and store the builderemail and manageremail in list, then provide as datasource to dropdown list

XmlDocument doc = new XmlDocument();
    doc.Load(@"sample.xml");
    XmlNodeList builderNodes =  doc.GetElementsByTagName("builderemail");
    XmlNodeList mangerNodes = doc.GetElementsByTagName("manageremail");


    List<string> builderMails = new List<string>();
    foreach (XmlNode node in builderNodes[0].ChildNodes)
    {
        builderMails.Add(node.Attributes["value"].Value);
    }

    List<string> mangerMails = new List<string>();
    foreach (XmlNode node in mangerNodes[0].ChildNodes)
    {
        mangerMails.Add(node.Attributes["value"].Value);
    }


     comboBox1.DataSource = builderMails;
        comboBox2.DataSource = mangerMails;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜