开发者

New help converting XML Data Set, Datarid to HTML output using C#, .NEt 2.0

开发者 https://www.devze.com 2022-12-21 08:49 出处:网络
In a new class I\'m writing, I need to take the contents of an external XML data feed and convert it into an HTML table via C# and .NET 2.0 (cannot go any higher due to server constraints). Since we r

In a new class I'm writing, I need to take the contents of an external XML data feed and convert it into an HTML table via C# and .NET 2.0 (cannot go any higher due to server constraints). Since we reuse the code, I'm putting this functionality开发者_C百科 into a class. Here is the XML Loader class:

using System;
using System.Web;
using System.Data;
using System.Text;
using System.Diagnostics;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace 
{
    public partial class XMLLoader
    {
        private String xmlpath = "\\xml\\data_test.xml";

    public String getXMLData()
    {
        DataSet dsXMLData = new DataSet("xml_data");
        string filePath = xmlpath;
        dsXMLData.ReadXml(filePath);
        Debug.WriteLine(dsXMLData.GetXml());

        DataGrid DataGrid1 = new DataGrid();
        DataGrid1.AllowPaging = true;
        DataGrid1.DataSource = dsXMLData;
        DataGrid1.DataMember = "xml_data";

        StringBuilder outStr = new  StringBuilder(String.Empty);
        outStr.Append(dsXMLData.GetXml());
        return outStr.ToString();
    }
}
}

Where I am getting stuck is outputting the contents of the data grid to an HTML Table using the outStr var which I am simply writing to the APSX page using <% Response.Write(); %>. Either way I'm stuck and so far not finding what I want to display in MSDN.


You need to call the method Databind() to your datagrid and add your datagrid to your page controls.

EDIT:

You can also use the method Render(yourHTMLTextWriter) of your datagrid after the binding

0

精彩评论

暂无评论...
验证码 换一张
取 消