| |
Sign In
<!-- ASPX usage --><xyz:VerticalGrid ID="vGrid" runat="server" />// sample databinding...this.vGrid1.DataSource = new DataView(dataSet1.Tables[0]);this.vGrid1.DataBind();/// <summary>/// A Repeater control that shows the rows and columns inverted. /// No template is required for the items./// The datasource must be an ADO.Net DataView/// </summary>[ToolboxData("<{0}:VerticalGrid runat=server></{0}:VerticalGrid>")]public class VerticalGrid : Repeater{ public VerticalGrid() { this.EnableViewState = false; } protected override void Render(HtmlTextWriter writer) { // invert the rows and cols if (!(base.DataSource is DataView)) throw new Exception("Error: only a dataview datasource can be used"); DataView dv = base.DataSource as DataView; // output start of table writer.Write("\n<table class='grid'>"); // output each row for (int i = 0; i < dv.Table.Columns.Count; i++) { writer.Write("\n<tr class='{0}'><th>{1}</th>", i % 2 == 1 ? "gI" : "gA", dv.Table.Columns[i].ColumnName); // output the column name in the first cell. class names gI and gA are abbreviations of gridItem gridAlternatingItem, to reduce output markup. for (int j = 0; j < dv.Count; j++) writer.Write("<td>{0}</td>", dv[j].Row.IsNull(i) ? " " : dv[j][i].ToString()); writer.Write("</tr>"); } writer.Write("\n</table>"); }}
Remember Me