table at run ime
-
I want to generate a table at run time in a panel.I want 5 columns in each row. here is code- Table tbl = new Table(); tbl.Style.Add("text-align", "center"); foreach (DataRow dr in dt.Rows) { TableRow tr = new TableRow(); TableCell tc1 = new TableCell(); TableCell tc2 = new TableCell(); TableCell tc3 = new TableCell(); TableCell tc4 = new TableCell(); TableCell tc5 = new TableCell(); tc1.BackColor = Color.WhiteSmoke; tc2.BackColor = Color.WhiteSmoke; tc3.BackColor = Color.WhiteSmoke; tc4.BackColor = Color.WhiteSmoke; tc5.BackColor = Color.WhiteSmoke; tc1.Width = 185; tc2.Width = 185; tc3.Width = 185; tc4.Width = 185; tc5.Width = 185; //tc1.BorderWidth = 1; //tc2.BorderWidth = 1; //tc3.BorderWidth = 1; //tc4.BorderWidth = 1; //tc5.BorderWidth = 1; tc1.Style.Add("text-align","center"); tc2.Style.Add("text-align","center"); tc3.Style.Add("text-align","center"); tc4.Style.Add("text-align","center"); tc5.Style.Add("text-align","center"); tr.Width = 926; tr.Height = 23; tr.BorderWidth = 1; tr.Controls.Add(tc1); tr.Controls.Add(tc2); tr.Controls.Add(tc3); tr.Controls.Add(tc4); tr.Controls.Add(tc5); //tc.Width = 110; //tc.Height = 22; //tc.Font.Size = 40; tc1.Text = "Niraj jain"; //tr.Controls.Add(tc); tbl.Controls.Add(tr); } Panel5.Controls.Add(tbl); but this table is not generating inside the panel.It is below the panel. plz help....
-
I want to generate a table at run time in a panel.I want 5 columns in each row. here is code- Table tbl = new Table(); tbl.Style.Add("text-align", "center"); foreach (DataRow dr in dt.Rows) { TableRow tr = new TableRow(); TableCell tc1 = new TableCell(); TableCell tc2 = new TableCell(); TableCell tc3 = new TableCell(); TableCell tc4 = new TableCell(); TableCell tc5 = new TableCell(); tc1.BackColor = Color.WhiteSmoke; tc2.BackColor = Color.WhiteSmoke; tc3.BackColor = Color.WhiteSmoke; tc4.BackColor = Color.WhiteSmoke; tc5.BackColor = Color.WhiteSmoke; tc1.Width = 185; tc2.Width = 185; tc3.Width = 185; tc4.Width = 185; tc5.Width = 185; //tc1.BorderWidth = 1; //tc2.BorderWidth = 1; //tc3.BorderWidth = 1; //tc4.BorderWidth = 1; //tc5.BorderWidth = 1; tc1.Style.Add("text-align","center"); tc2.Style.Add("text-align","center"); tc3.Style.Add("text-align","center"); tc4.Style.Add("text-align","center"); tc5.Style.Add("text-align","center"); tr.Width = 926; tr.Height = 23; tr.BorderWidth = 1; tr.Controls.Add(tc1); tr.Controls.Add(tc2); tr.Controls.Add(tc3); tr.Controls.Add(tc4); tr.Controls.Add(tc5); //tc.Width = 110; //tc.Height = 22; //tc.Font.Size = 40; tc1.Text = "Niraj jain"; //tr.Controls.Add(tc); tbl.Controls.Add(tr); } Panel5.Controls.Add(tbl); but this table is not generating inside the panel.It is below the panel. plz help....
Any particular reason you're not using a gridview?
-
I want to generate a table at run time in a panel.I want 5 columns in each row. here is code- Table tbl = new Table(); tbl.Style.Add("text-align", "center"); foreach (DataRow dr in dt.Rows) { TableRow tr = new TableRow(); TableCell tc1 = new TableCell(); TableCell tc2 = new TableCell(); TableCell tc3 = new TableCell(); TableCell tc4 = new TableCell(); TableCell tc5 = new TableCell(); tc1.BackColor = Color.WhiteSmoke; tc2.BackColor = Color.WhiteSmoke; tc3.BackColor = Color.WhiteSmoke; tc4.BackColor = Color.WhiteSmoke; tc5.BackColor = Color.WhiteSmoke; tc1.Width = 185; tc2.Width = 185; tc3.Width = 185; tc4.Width = 185; tc5.Width = 185; //tc1.BorderWidth = 1; //tc2.BorderWidth = 1; //tc3.BorderWidth = 1; //tc4.BorderWidth = 1; //tc5.BorderWidth = 1; tc1.Style.Add("text-align","center"); tc2.Style.Add("text-align","center"); tc3.Style.Add("text-align","center"); tc4.Style.Add("text-align","center"); tc5.Style.Add("text-align","center"); tr.Width = 926; tr.Height = 23; tr.BorderWidth = 1; tr.Controls.Add(tc1); tr.Controls.Add(tc2); tr.Controls.Add(tc3); tr.Controls.Add(tc4); tr.Controls.Add(tc5); //tc.Width = 110; //tc.Height = 22; //tc.Font.Size = 40; tc1.Text = "Niraj jain"; //tr.Controls.Add(tc); tbl.Controls.Add(tr); } Panel5.Controls.Add(tbl); but this table is not generating inside the panel.It is below the panel. plz help....
-
You have used Controls.Add method everywhere. Use TableRow.Cells.Add([New Control]") method appropriately. Ex: tr.Cells.Add(tc1); tb1.Rows.Add(tr); I have tried it and its working :)