0

我想使用我的 SQL 表格结果在 aspx 页面中创建表格,并在我的网页上填充表格行、列和单元格。

我将我的问题分为 3 个步骤,如下图所示。

在此处输入图像描述

这是2,3步骤

在此处输入图像描述

这是我显示结果的代码

可以只显示第 1 步

    DataClassesDataContext conx = new DataClassesDataContext();
    var resulttable =
              from s in conx.tbl_UserAnswers
              group s by  s.Matrixy into g
              select new
              {
                  rowKey = g.Key,
                  rowData = g.Select(s => new { result = s.result, Amount = s.landa })//.OrderBy(s => s.Product.Label)
              };
    // Create a new HtmlTable object.
    HtmlTable table1 = new HtmlTable();
    HtmlTableRow row;
    HtmlTableCell cell;     
    foreach (var tableRow in resulttable)
    {
        // Create a new row and set its background color.
        row = new HtmlTableRow();
        foreach (var sale in tableRow.rowData)
        {
            // Create a cell and set its text.
            cell = new HtmlTableCell();
            cell.InnerHtml = sale.result.ToString(); 
            tableRow.rowKey.Value.ToString();// "Row: ";//+ i.ToString()+ "<br />Cell: " + j.ToString();
            // Add the cell to the current row.
            row.Cells.Add(cell);
        }
        // Add the row to the table.
        table1.Rows.Add(row);
    }

    // Add the table to the page.
    myPlaceHolder.Controls.Add(table1);
}
4

0 回答 0