HI friends ,In this article i'd wish to justify "how to bind XML Datasource to Dropdown list" simply follow the steps clearly
First we want to make a XML file to store the info.suppose you'd wish to store contries information in xml file and bind that information to Dropdown list
- Add new Xml file to your existing Aspnet project
- copy the subsequent code in to XML file
- save the file with countries.xml
- now open the page that contains Gridview
- Currently add the subsequent code for your gridview.In the below code , i'm added One Xml datasource that is offered in our tool cabinet.just Drag and Drop the Xml datasource.then simply add the Datasource ID of the drop downlist
Code Here:
<?xml version="1.0" encoding="utf-8" ?>
<Countries>
<Country name="India" value="1"></Country>
<Country name="America" value="2"></Country>
<Country name="France" value="3"></Country>
<Country name="Saudi" value="4"></Country>
<Country name="Srilanka" value="5"></Country>
</Countries>
Next Code-:
<asp:TemplateField HeaderText="DOB">
<ItemTemplate>
<asp:Label ID="lbl_ct" runat="server" Text='<%# Bind("country")%>'>>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddl_ct" AutoPostBack="True"
DataTextField="name" DataValueField="value" runat="server"
AppendDataBoundItems="True" DataSourceID="countries"
SelectedValue='<%# Bind("country", "{0}") %>' >
</asp:DropDownList>
<asp:XmlDataSource ID="countries" runat="server" DataFile="~/XmlDataSource/countries.xml">
</asp:XmlDataSource>
</EditItemTemplate>
</asp:TemplateField>
No comments:
Post a Comment