使用c#和ASP.NET在页面上填充SQL表结果的表格单元格

时间:2012-12-06 07:27:28

标签: c# asp.net

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

我将问题分成下面图片中的3个步骤。

enter image description here

这是2,3步

enter image description here

这是我显示结果的代码

可以显示第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);
}

0 个答案:

没有答案