DriverId OrderCount OrderCountWhereNameIsNotNull
12 2 2
13 1 1
this is the current table which is being made by this code:
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();
}
}
instead of the table I need to take and print for each DriverId a progress bar as in this script:
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;'> </div>";
oDiv.InnerHtml += Environment.NewLine + "</div>";
oCell.Controls.Add(oDiv);
oRow.Cells.Add(oCell);
tblData.Rows.Add(oRow);
}
I cannot combine them, may be the script is not good...please help
at the moment my main page is:
<form id="Form1" runat="server">
<asp:GridView runat="server" ID="DataViewer">
</asp:GridView>
</form>
You will probably find it simpler to bind your grid to your dataset, rather than building a table that attempts to inject itself into a grid:
<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>