Search This Blog

Tuesday, September 18, 2012

Populate drop down list with XML in C#

Create XML File  named CollectionModeinSales.xml in root folder:

<?xml version="1.0" encoding="utf-8" ?>
<CollectionModes>
  <CollectionMode>
    <text>Cash</text>
    <value>Cash</value>
 
</CollectionMode>
  <CollectionMode>
    <text>Cheque</text>
    <value>Cheque</value>
  </CollectionMode>

  <CollectionMode>
    <text>D.D</text>
    <value>D.D</value>
  </CollectionMode>

  <CollectionMode>
    <text>TT</text>
    <value>TT</value>
  </CollectionMode>

  <CollectionMode>
    <text>Credit</text>
    <value>Credit</value>
  </CollectionMode>

</CollectionModes>





Add asp:DropDownList in ASPX file

 <asp:DropDownList ID="ddlCollectionType" runat="server" Width="106px">
                                                                   </asp:DropDownList>

C# Code behind file:

            DataSet dsCollectionType = new DataSet();
           
    dsCollectionType.ReadXml(AppDomain.CurrentDomain.BaseDirectory + "CollectionModeinSales.xml");
    ddlCollectionType.DataSource = dsCollectionType.Tables[0];
    ddlCollectionType.DataTextField = "text";
    ddlCollectionType.DataValueField ="value";
    ddlCollectionType.DataBind();


No comments:

Post a Comment