新的帮助使用C#转换XML数据集,Datarid到HTML输出,.NET 2.0 [英] New help converting XML Data Set, Datarid to HTML output using C#, .NEt 2.0

查看:284
本文介绍了新的帮助使用C#转换XML数据集,Datarid到HTML输出,.NET 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个新的类,我写,我需要一个外部XML数据文件的内容,并通过C#和.NET 2.0将其转换成一个HTML表(不能去任何更高,由于服务器的限制)。因为我们重用code,我把这个功能集成到一个类。下面是XML Loader类:

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 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();
    }
}
}

我在哪里卡住使用outStr无功而我只是写APSX页面使用&LT的输出数据网格的内容到HTML表;%的Response.Write(); %>。无论哪种方式,我被困,至今没有找到我想要在MSDN中显示。

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.

推荐答案

您需要调用方法数据绑定()您的DataGrid和您的DataGrid添加到您的页面控件

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

编辑:

您也可以使用方法渲染(yourHTMLTextWriter)后您的DataGrid中的结合

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

这篇关于新的帮助使用C#转换XML数据集,Datarid到HTML输出,.NET 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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