asp.net - RowSpan and alternate row color at the same time using c# -



asp.net - RowSpan and alternate row color at the same time using c# -

i trying utilize row span on 1 column (if value of next row same) , alternate row color according above situation.

i managed row span working way wanted can`t alternate rows. batchno: 3694217 row should bluish aswell.

here current output:

asp

<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; (int = visualisation.rows.count - 2; >= 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; } } }

you need maintain separate counter of rows assign alternating colors. note in current code colors alternate if rows spanned, hence single row not hghlighted. around should trick:

protected void ondatabound(object sender, eventargs e) { int rowspan = 2; // actual row counter, spanned rows count 1 int rowcount = 0; (int = visualisation.rows.count - 2; >= 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; } else { rowspan = 2; //it new row rowcount++; } if (rowcount % 2 == 0) { currrow.backcolor = color.fromname("#7aa5d6"); } } }

c# asp.net gridview

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -