脚本之间的结合

时间:2011-11-05 16:36:05

标签: c# asp.net linq entity-framework linq-to-entities

DriverId      OrderCount      OrderCountWhereNameIsNotNull
12               2                         2
13               1                         1

这是此代码制作的当前表格:

 public partial class Control : System.Web.UI.Page
    {



        protected void Page_Load(object sender, EventArgs e)
    {
        OrderDataRepository rep = new OrderDataRepository();

        var results = rep.GetAllOrderData().
                      GroupBy(o => o.DRIVER_ID).
                      Select(g =>
                                new
                                {
                                    DriverId = g.Key,
                                    OrderCount = g.Count(),
                                    OrderCountWhereNameIsNotNull = 
                                                      g.Count(o => o.RECEIVE_NAME != null)
                                }).ToList();

        DataViewer.DataSource = results;
        DataViewer.DataBind();
    }

    }

而不是表格,我需要为每个DriverId拍摄并打印一个进度条,如下所示:

  int OrderCount, OrderCountWhereNameIsNotNull;
System.Web.UI.WebControls.TableRow oRow;
System.Web.UI.WebControls.TableCell oCell;
System.Web.UI.HtmlControls.HtmlGenericControl oDiv;

while (true)
//loop through records
//do while not eof
{
    oRow = new System.Web.UI.WebControls.TableRow();
    oCell = new System.Web.UI.WebControls.TableCell();
    oDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
    OrderCount = 200; //get value from DB, convert to meaningful width
    OrderCountWhereNameIsNotNull = 100; //get value from DB, convert to meaningful width

    oDiv.InnerHtml = "<div style='border: 3px solid black; width: " + OrderCount + "px;'>";
    oDiv.InnerHtml += Environment.NewLine + "  <div style='border: 0px; background-color: red; width: " + OrderCountWhereNameIsNotNull + "px;'>&nbsp;</div>";
    oDiv.InnerHtml += Environment.NewLine + "</div>";
    oCell.Controls.Add(oDiv);
    oRow.Cells.Add(oCell);
    tblData.Rows.Add(oRow);
}

我无法将它们合并,可能是剧本不好......请帮忙

目前我的主页是:

<form id="Form1" runat="server">
        <asp:GridView runat="server" ID="DataViewer">
        </asp:GridView>
    </form>

enter image description here

1 个答案:

答案 0 :(得分:0)

您可能会发现将网格绑定到数据集更简单,而不是构建一个尝试将自身注入网格的表:

<asp:GridView ID="DataViewer" runat="server">
    <Columns>
        <TemplateColumn>
            <ItemTemplate>
Put the code for rendering your progress bar here in pure HTML. 
When you come to a value that will come from a row in your data, do like this:
<div style='width: <%# Eval("OrderCount") %>' />
            </ItemTemplate>
        </TemplateColumn>
    </Columns>
</asp:GridView>