2016-03-23 14 views
2

プログラムで生成されたテーブルの表示に問題があります。私に説明させてください。.aspx-websiteでプログラムで生成されたテーブルを表示する方法

<?xml version="1.0" encoding="utf-8" ?> 
<Fragebogen> 
    <Header>Header</Header> 
    <Tables> 
    <Table> 
     <Rows> 
     <Row> 
      <Cells> 
      <Cell>Cell 1 Row 1</Cell> 
      </Cells> 
     </Row> 
     <Row> 
      <Cells> 
      <Cell>Cell 1 Row 2</Cell> 
      </Cells> 
     </Row> 
     <Row> 
      <Cells> 
      <Cell>Cell 1 Row 3</Cell> 
      <Cell>Cell 2 Row 3</Cell> 
      <Cell>Cell 3 Row 3</Cell> 
      </Cells> 
     </Row> 
     </Rows> 
    </Table> 
    </Tables> 
</Fragebogen> 

この方法:

if (String.IsNullOrWhiteSpace(file) && node == null) return null; 

// If a file is not empty then load the xml and overwrite node with the 
// root element of the loaded document 
node = !String.IsNullOrWhiteSpace(file) ? XDocument.Load(file).Root : node; 

IDictionary<String, dynamic> result = new ExpandoObject(); 

// implement fix as suggested by [ndinges] 
var pluralizationService = 
    PluralizationService.CreateService(CultureInfo.CreateSpecificCulture("en-us")); 

// use parallel as we dont really care of the order of our properties 
node.Elements().AsParallel().ForAll(gn => 
{ 
    // Determine if node is a collection container 
    var isCollection = gn.HasElements && 
     (
     // if multiple child elements and all the node names are the same 
      gn.Elements().Count() > 1 && 
      gn.Elements().All(
       e => e.Name.LocalName.ToLower() == gn.Elements().First().Name.LocalName) || 

      // if there's only one child element then determine using the PluralizationService if 
     // the pluralization of the child elements name matches the parent node. 
      gn.Name.LocalName.ToLower() == pluralizationService.Pluralize(
       gn.Elements().First().Name.LocalName).ToLower() 
     ); 

    // If the current node is a container node then we want to skip adding 
    // the container node itself, but instead we load the children elements 
    // of the current node. If the current node has child elements then load 
    // those child elements recursively 
    var items = isCollection ? gn.Elements().ToList() : new List<XElement>() { gn }; 

    var values = new List<dynamic>(); 

    // use parallel as we dont really care of the order of our properties 
    // and it will help processing larger XMLs 
    items.AsParallel().ForAll(i => values.Add((i.HasElements) ? 
     GetExpandoFromXml(null, i) : i.Value.Trim())); 

    // Add the object name + value or value collection to the dictionary 
    result[gn.Name.LocalName] = isCollection ? values : values.FirstOrDefault(); 
}); 
return result; 

はExpandoで、オブジェクトにノードを取得している 私はこのように見ているXMLを持っています。このオブジェクトを使用して、私はプログラムでaspx-websiteにテーブルを生成したいと思います。生成するために、私はこのメソッドを呼び出しています:

dynamic fragebogen = GetExpandoFromXml(SSG.Fragebogen.Properties.Settings.Default.ConfigPath); 
var header = fragebogen.Header; 
var tables = fragebogen.Tables; 
Table t; 
var rows = tables[0].Rows; 
TableRow r; 
dynamic cells = null; 
for (int i = 0; i < rows.Count; i++) 
{ 
    cells = rows[i].Cells; 
} 
TableCell c; 

foreach (var table in tables) 
{ 
    t = new Table(); 
    foreach (var row in rows) 
    { 
     r = new TableRow(); 
     t.Rows.Add(r); 
     foreach (var cell in cells) 
     { 
      c = new TableCell(); 
      c.Text = cell; 
      r.Cells.Add(c); 
     } 
    } 
} 

これまでのところすべてが問題ありません。行とセルはすべて適切な値でテーブルに追加され、例外やその他のものはありません。しかしテーブルはWebサイトに表示されません。 何も表示されていない理由がわからないので、あなたが私を助けてくれることを願っています。

+0

あなたは私たちにすべてのそのコードを表示する必要はありませんし、コード上の背後にあるように、そのホルダーに、あなたのテーブルを配置

<asp:PlaceHolder runat="server" ID="phOnme"></asp:PlaceHolder> 

としてあなたのページにプレースホルダを置きますそれは単なる気晴らしです。あなたの問題はページ上のテーブルを取得しています。これを行う多くの方法の1つが[ここで実証されました](https://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmltable(v = vs.110).aspx) – Crowcoder

答えて

3

この動的生成テーブルを表示するには、ページのどこかに追加する必要があります。 、あなたのHTMLが正しく構築されている場合は

Table t; 
// generate the table... 
// add it to page. 
phOnme.Controls.Add(t); 
+1

ありがとう、それは問題を解決しました! –

関連する問題