<?xml version="1.0" encoding="utf-8" ?>
<users>
<user>
<FirstName>Suresh</FirstName>
<LastName>Dasari</LastName>
<UserName>SureshDasari</UserName>
<Job>Team Leader</Job>
</user>
<user>
<FirstName>Mahesh</FirstName>
<LastName>Dasari</LastName>
<UserName>MaheshDasari</UserName>
<Job>Software Developer</Job>
</user>
<user>
<FirstName>Madhav</FirstName>
<LastName>Yemineni</LastName>
<UserName>MadhavYemineni</UserName>
<Job>Business Analyst</Job>
</user>
</users>
|
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Read Data from XML and Bind Data to gridview/dropdownlist
in asp.net</title>
</head>
<body>
<form id="form1"
runat="server">
<table>
<tr>
<td><b>Dropdown List</b></td>
<td><asp:DropDownList ID="ddlDetails"
runat="server"/></td>
</tr>
<tr>
<td><b>Gridview Details</b></td>
<td>
<asp:GridView ID="gvDetails"
runat="server">
<HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
</asp:GridView>
</td>
</tr>
</table>
</form>
</body>
</html>
|
using System;
using System.Data;
using System.Xml;
|
protected void
Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindDataToGridviewDropdownlist();
}
}
// This method is used to bind
data to dropdownlist and gridview
protected void
BindDataToGridviewDropdownlist()
{
XmlTextReader xmlreader = new
XmlTextReader(Server.MapPath("Sample.xml"));
DataSet ds = new DataSet();
ds.ReadXml(xmlreader);
xmlreader.Close();
if (ds.Tables.Count != 0)
{
//Bind Data to gridview
gvDetails.DataSource = ds;
gvDetails.DataBind();
//Bind Data to dropdownlist
ddlDetails.DataSource = ds;
ddlDetails.DataTextField = "UserName";
ddlDetails.DataValueField = "UserName";
ddlDetails.DataBind();
}
}
|
Imports System.Data
Imports System.Xml
Partial Class
VBSample
Inherits System.Web.UI.Page
Protected Sub
Page_Load(ByVal sender As Object, ByVal e As
EventArgs) Handles Me.Load
If Not IsPostBack Then
BindDataToGridviewDropdownlist()
End If
End Sub
' This method is used to bind
data to dropdownlist and gridview
Protected Sub
BindDataToGridviewDropdownlist()
Dim xmlreader As New XmlTextReader(Server.MapPath("Sample.xml"))
Dim ds As New DataSet()
ds.ReadXml(xmlreader)
xmlreader.Close()
If ds.Tables.Count <> 0 Then
'Bind Data to gridview
gvDetails.DataSource = ds
gvDetails.DataBind()
'Bind Data to dropdownlist
ddlDetails.DataSource = ds
ddlDetails.DataTextField = "UserName"
ddlDetails.DataValueField = "UserName"
ddlDetails.DataBind()
End If
End Sub
End Class
|
|
|
|
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|

Subscribe by RSS
Subscribe by Email
5 comments :
hkkk
Please give an example of Bulk Insert, Bulk Update using XML file and C# which is widely used in projects in companies.
good job
All articles in this properly descriptive and elegant.
hi..i need more steps to excecute and how to save this codes.