How to show xml data into dropdownlist in asp.net. [Resolved]

Posted by Shweta_Pinky under ASP.NET on 8/31/2013 | Points: 10 | Views : 1256 | Status : [Member] | Replies : 2
How to show xml data into dropdownlist in asp.net.
Here is the xml below
<?xml version="1.0" encoding="utf-8"?>
<studentdata>
<student>
<sid>1</sid>
<sname>Tim</sname>
<smarks>100</smarks>
<saddress>Sydney</saddress>
</student>
<student>
<sid>2</sid>
<sname>Jack</sname>
<smarks>90</smarks>
<saddress>Perth</saddress>
</student>
</studentdata>

Output in dropdownlist
1Tim100Sydney
2 Jack90Perth




Responses

Posted by: Satyapriyanayak on: 8/31/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication3.WebForm1" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
</asp:DropDownList>
</div>
</form>
</body>
</html>



Imports System.Xml
Partial Public Class WebForm1
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim xd1 As New XmlDocument

xd1.Load(Server.MapPath("student.xml"))
Dim xnl1 As XmlNodeList
xnl1 = xd1.SelectNodes("studentdata/student")
For Each stdname As XmlNode In xnl1
DropDownList1.Items.Add(stdname.InnerText)
Next
End Sub

End Class


If this post helps you mark it as answer
Thanks

Shweta_Pinky, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 8/31/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
refer this link
http://asp-net-example.blogspot.in/2008/10/dropdownlist-example-how-to-populate.html

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shweta_Pinky, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response