我想在1列上使用行跨度(如果下一行的值相同) 並根據上述情況交替排列顏色。RowSpan和備用行顏色同時使用c#
我設法讓行跨度按我想要的方式工作,但不能交替行。批號:3694217行應該是藍色的。
下面是電流輸出:
天冬氨酸
<asp:GridView ID="visualisation" runat="server"
AutoGenerateColumns="false" OnDataBound="OnDataBound" OnItemDataBound="Item_Bound" CellPadding="15" CellSpacing="15" HeaderStyle-BackColor="DarkOliveGreen" GridLines="Both">
<Columns>
<asp:BoundField DataField="BatchNo" HeaderText="BatchNo" HeaderStyle-Width="15%" />
<asp:BoundField DataField="Type" HeaderText="Type" HeaderStyle-Width="15%" />
<asp:ImageField DataImageUrlField="DataLoaded" HeaderText="DataLoaded" HeaderStyle-Width="15%" />
<asp:ImageField DataImageUrlField="Errors" HeaderText="Errors" HeaderStyle-Width="15%" />
<asp:ImageField DataImageUrlField="ProcessingRun" HeaderText="ProcessingRun" HeaderStyle-Width="15%" />
</Columns>
</asp:GridView>
C#
protected void Page_Load(object sender, EventArgs e)
{
dataT();
visualisation.DataBind();
}
public void dataT()
{
DataTable dtVisu = new DataTable();
dtVisu.Columns.Add(new DataColumn("BatchNo", typeof(System.String)));
dtVisu.Columns.Add(new DataColumn("Type", typeof(System.String)));
dtVisu.Columns.Add(new DataColumn("DataLoaded", typeof(System.String)));
dtVisu.Columns.Add(new DataColumn("Errors", typeof(System.String)));
dtVisu.Columns.Add(new DataColumn("ProcessingRun", typeof(System.String)));
//dtVisu.Columns.Add(new DataColumn("alignRow", typeof(System.String)));
DataRow dr = dtVisu.NewRow();
dr["BatchNo"] = "3704500";
dr["Type"] = "Calibration";
dr["DataLoaded"] = "images/g4-12.png";
dr["Errors"] = "images/g4-12.png";
dr["ProcessingRun"] = "images/g4-12.png";
//dr["alignRow"] = "1";
dtVisu.Rows.Add(dr);
dr = dtVisu.NewRow();
dr["BatchNo"] = "3704542";
dr["Type"] = "Range Settings";
dr["DataLoaded"] = "images/r4-12.png";
dr["Errors"] = "images/r4-12.png";
dr["ProcessingRun"] = "images/g4-12.png";
dtVisu.Rows.Add(dr);
dr = dtVisu.NewRow();
dr["BatchNo"] = "3704542";
dr["Type"] = "Range Settings";
dr["DataLoaded"] = "images/r4-12.png";
dr["Errors"] = "images/r4-12.png";
dr["ProcessingRun"] = "images/g4-12.png";
dtVisu.Rows.Add(dr);
dr = dtVisu.NewRow();
dr["BatchNo"] = "3687345";
dr["Type"] = "Calibration";
dr["DataLoaded"] = "images/g4-12.png";
dr["Errors"] = "images/g4-12.png";
dr["ProcessingRun"] = "images/g4-12.png";
dtVisu.Rows.Add(dr);
dr = dtVisu.NewRow();
dr["BatchNo"] = "3694217";
dr["Type"] = "Calibration";
dr["DataLoaded"] = "images/g4-12.png";
dr["Errors"] = "images/g4-12.png";
dr["ProcessingRun"] = "images/g4-12.png";
dtVisu.Rows.Add(dr);
visualisation.DataSource = dtVisu;
}
protected void OnDataBound(object sender, EventArgs e)
{
int RowSpan = 2;
for (int i = visualisation.Rows.Count - 2; i >= 0; i--)
{
GridViewRow currRow = visualisation.Rows[i];
GridViewRow prevRow = visualisation.Rows[i + 1];
if (currRow.Cells[0].Text == prevRow.Cells[0].Text)
{
currRow.Cells[0].RowSpan = RowSpan;
prevRow.Cells[0].Visible = false;
RowSpan += 1;
currRow.BackColor = Color.FromName("#7AA5D6");
prevRow.BackColor = Color.FromName("#7AA5D6");
}
else
{
RowSpan = 2;
}
}
}
我沒有看到任何代碼,除了兩個顏色的任何行。另外,你爲什麼要以相反的順序遍歷行? – BCdotWEB 2014-10-10 12:54:35
我無法得到它的工作,這就是爲什麼我從未包含顏色的代碼。倒序的原因是我不會得到空值,我可以很容易地比較它們 – emre 2014-10-10 13:01:39