displaying XML data in datagrid column

  • Thread starter Thread starter Nedu N
  • Start date Start date
N

Nedu N

i want to display actual XML data (with tags & data) from a table's colum
(XML data) in a datagrid's column...

by default it shows only yhe content of the XML but not the tags...anyone
have an answer for this...

i don't want to bind the data to a text box/lable in order to overcome
this..
 
Hi Nedu,

How did you bind the XML data to the datagrid? Normally, we can first
convert a XML file to a DataSet, and then bind the datagird to the dataset.
For example, we have a XML file "XMLFile1.xml":

<?xml version="1.0" encoding="utf-8" ?>
<Books>
<book>
<id> 1</id>
<name> One</name>
</book>

<book>
<id> 2</id>
<name> Two</name>
</book>

<book>
<id> 3</id>
<name> Three</name>
</book>

</Books>

In an ASPNET application, we can use following code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load


Dim ds As New DataSet

ds.ReadXml(Server.MapPath("\webapplication1\xmlfile1.xml"))

DataGrid1.DataSource = ds.Tables(0)

DataGrid1.DataBind()

End Sub

And then the XML data with be shown the datagrid. As you seen, the tag <id>
and <name> will be used as column name in the datagrid.

Luke
Microsoft Online Partner Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Nedu N said:
i want to display actual XML data (with tags & data) from a table's colum
(XML data) in a datagrid's column...

by default it shows only yhe content of the XML but not the tags...anyone
have an answer for this...

i don't want to bind the data to a text box/lable in order to overcome
this..

You can use Server.HtmlEncode to achieve the required result:

<ItemTemplate><%# Server.HtmlEncode(DataBinder.Eval(Container.DataItem,
"xml"), 0) %></ItemTemplate>
 
Back
Top