XML对象绑定到gridView [英] XML Object Binding to to gridView

查看:52
本文介绍了XML对象绑定到gridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个解析的xml对象,我需要绑定到网格视图.但是我的问题是这个对象在其中包含了集合和子集合.所有这些我都需要绑定到单个网格视图.

Hi,

I have a parsed object of xml, that i need to bind to grid view.But my problem is this object contains collection and subcollections inside that. all these things i need to bind to a single grid view. can any one help me with good and simple approach?

推荐答案

绑定xml文件并在网格视图中显示xml文件的数据.这是代码

Bind xml file and display data of xml file in grid view . here is the code

<script  runat="server">
    void Page_Load(Object sender, EventArgs e)
    {
        DataSet authorsDataSet;
        string filePath = Server.MapPath("Authors.xml");
        authorsDataSet = new DataSet();
        //Read the contents of the XML file into the DataSet
        authorsDataSet.ReadXml(filePath);                    
        authorsGird.DataSource = authorsDataSet.Tables[0].DefaultView;
        authorsGird.DataBind();
    }
</script>



以下是网格视图的html标记



below is the html markup of grid view

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Reading XML Data into a DataSet object </title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView id="authorsGird" runat="server"

            AutoGenerateColumns="False" CellPadding="4" HeaderStyle-BackColor="blue" HeaderStyle-ForeColor="White"

            HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="True">
            <Columns>
                <asp:BoundField HeaderText="Last Name" DataField="lastName" />
                <asp:BoundField HeaderText="First Name"

                    DataField="firstName" ItemStyle-HorizontalAlign="Right" />
            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
</html>


这篇关于XML对象绑定到gridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆