A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Creating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.
Binding a DataGrid to an XML fileThis tutorial will show you how to bind a DataGrid to a simple XML file so you can display the values as rows and the tags as columns. |
On Tuesday, November 2nd 2004 at 09:32 AM By Andrew Pociu (View Profile) ![]() ![]() ![]() ![]() (Rated 4.4 with 30 votes) |
||||||||
|
Start a new ASP .NET Web Application project. From the Solution Explorer window right click the project and choose Add -> New Item. From the Add New Item window choose XML File. In the name textbox enter Movies.xml. This will be the XML file we will work with and we're going to store information about some movies in it. Now that it is added to the project, open it. This is the only line you'll find in it:
I suppose you have at least the basic knowledge of the structure of an XML file if you're interested in reading it using ASP .NET and C#. So inside the XML file let's add these 3 movies:
Now open the main WebForm, WebForm1.aspx and drag a DataGrid on it from the Toolbox. As a result of adding the DataGrid the <asp:DataGrid> tag is created inside WebForm1.aspx:
We want the data inside the XML file to be displayed in the DataGrid. So open WebForm1.aspx.cs and we'll bind the DataGrid to the XML file. We can see that the DataGrid DataGrid1 was created here:
So let's bind it. We'll do this in Page_Load.
For reading the XML file we need a DataSet which we created. The commented code is really easy to follow.
Now run the code and see the result. ![]() The code creates a simple DataGrid holding the data from the XML file. Of course, most of the time you'll want to select the columns which you want to appear in the DataGrid, for example you might not be interested to have a column with the year in which the movie was created, you want just the title and genre. This is easily accomplished, the same way you do it when working with databases. You set the AutoGenerateColumns attribute to False and use <asp:BoundColumn> tags to select which tags / columns you want to be displayed:
Further, if you want to make the DataGrid more esthetic, the tutorial 'Basics of using DataGrid' will show you how. |
|||||||||
Digg It!
Del.icio.us
Reddit
StumbleIt
Newsvine
Furl
BlinkList
|
|||||||||
|
|||||||||
Current CommentsVery good and useful.Can somebody help me by giving an asp.net project
Very good and useful.Can somebody help me by giving an asp.net project
very useful indeed!
GREAT example.. Exactly what I needed.. THANX!
It really helps a lot !
Great !
Good
Thank you... short and sweet.
Good work...!!!!!!!!!
Short Key For A Big Lock
Binding XML to DataGrid
Hi guys!
The following link shows a tutorial that walks you through the steps to bind an xml file to a datagrid. The same website has a chat room and I try to spend a lot of time there answering people\'s question. Stop by if you want.
:)
http://www.kynou.com/GetTutorial.aspx?TutorialID=65
hey what are doing
what is wrong in the following code?
I need to bind an xml file to a datagrid.... However when I run this code in browser I just get a blank page.....
<%@ Page Language=\"VB\" AutoEventWireup=\"false\" CodeFile=\"Default.aspx.vb\" Inherits=\"_Default\" %>
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<%@Import Namespace=\"System.Data\" %>
<%@ Import Namespace=\"System.Data.SqlClient\" %>
<%@ Import Namespace=\"System.IO\" %>
<script runat=\"Server\">
Sub Page_Load ( Server As Object, E As EventArgs)
Dim fs As Filestream
fs = New FileStream(Server.MapPath(\"movies.xml\"), FileMode.Open, FileAccess.Read)
Dim Reader As StreamReader
Reader = New StreamReader(fs)
Dim ds As New DataSet
ds.ReadXml(Reader)
fs.Close()
Dim source As DataView
source = New DataView(ds.Tables(0))
DataGrid1.DataSource = source
DataGrid1.DataBind()
End Sub
</script>
<html xmlns=\"http://www.w3.org/1999/xhtml\" >
<head id=\"Head1\" runat=\"server\">
<title>Untitled Page</title>
</head>
<body>
<form id=\"form1\" runat=\"server\">
<div>
<asp:DataGrid ID=\"DataGrid1\" runat=\"server\" >
</asp:DataGrid></div>
</form>
</body>
</html>
Ya.Very Nice Example.
hi all,
i want to write xml file from a grid using XMLTextWriter with vb.net...
best Regards
Hamza Malakwi
Hey thanks a lot...
well explained...
Related Tutorials
Related Source Code
ASP.NET Job Search