using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace TestGridControl { [DefaultProperty("Text")] [ToolboxData("<{0}:TestGridControl runat="server">")] public class TestGridControl : Table { private int nrows; TableCell cell; public HyperLink hyp = new HyperLink(); public Label lbl = new Label(); TableRow row; Table table = new Table(); [Bindable(true)] [Category("Appearance")] [DefaultValue("")] [Localizable(true)] [Browsable(true)] public int NumberofRows { //Int32 s = (Int32)ViewState["NumberofRows"]; get { EnsureChildControls(); return nrows; } set { EnsureChildControls(); nrows = value; } } //public void CreateTable() //{ // cell = new TableCell(); // row = new TableRow(); // row.BackColor = System.Drawing.Color.Green; // row.Cells.Add(cell); // table.BorderColor = System.Drawing.Color.Black; // table.Width = 100; // table.Height = 100; // table.Rows.Add(row); //} protected override void RenderContents(HtmlTextWriter writer) { //writer.BeginRender(); this.CreateChildControls(); //writer.EndRender(); ////this.Render(writer); base.Render(writer); } protected override void CreateChildControls() { try { table.Width = 100; table.Height = 100; for (int i = 0; i < this.NumberofRows; i++) { cell = new TableCell(); row = new TableRow(); cell.Controls.Add(hyp); cell.Controls.Add(lbl); row.BackColor = System.Drawing.Color.Green; row.Cells.Add(cell); table.Width = 100; table.BorderColor = System.Drawing.Color.Red; table.Height = 100; table.Rows.Add(row); } table.DataBind(); this.Controls.Add(table); } catch (Exception ex) { Console.WriteLine("StackOverflow", ex.Message); ; } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)