displaying XML data in datagrid column

Discussion in 'ASP .Net Building Controls' started by Nedu N, Sep 17, 2003.

  1. Nedu N

    Nedu N Guest

    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..
     
    Nedu N, Sep 17, 2003
    #1
    1. Advertising

  2. Nedu N

    MSFT Guest

    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.)
     
    MSFT, Sep 18, 2003
    #2
    1. Advertising

  3. "Nedu N" <> wrote in message
    news:...
    > 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>

    --
    Henrik Grotle
     
    Henrik Grotle, Sep 18, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nedu N
    Replies:
    1
    Views:
    429
    Henrik Grotle
    Sep 18, 2003
  2. carlos perez
    Replies:
    0
    Views:
    423
    carlos perez
    Jun 8, 2004
  3. Nedu N

    displaying XML data in datagrid column

    Nedu N, Sep 17, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    118
  4. Nedu N

    displaying XML data in datagrid column

    Nedu N, Sep 17, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    129
    Henrik Grotle
    Sep 18, 2003
  5. Teej
    Replies:
    2
    Views:
    323
Loading...

Share This Page