Saturday, March 31, 2012

Table. Look Everywhere. Please help me out.

Hello,

I need to create a Table at runtime and I need the TBody tag to be:

<tbody id="itemContainer" runat="server"></tbody>

I need to to define its ID and making it run at server.

I tried everthing I could think of.

How can I do this?

Thanks,

Miguel

you can use a placeholder and do a placeholder.controls.add(pass the tablehere, table is your server object)


You didn't understand. I have no problems in working at runtime.

I create everything at runtime. The problem is that I can't find a property/way to define the ID of a Table's TBody tag when created at runtime.

Thanks,

Miguel


Hi Miguel,

Based on my understanding, you want to add the table in your asp.net application dynamically. If I have misunderstood you, please feel free to let me know.

The tbody is the html control. We can add the server table dynamically. For example,

Table t = new Table();
t.ID = "t";
TableHeaderRow hr = new TableHeaderRow();
hr.ID = "hr";
t.Controls.Add(hr);
TableCell tc = new TableCell();
tc.ID = "tc";
hr.Controls.Add(tc);
tc.Text = "test";

form1.Controls.Add(t);


I hope this helps.


publicvoid CreateEmployeeList()

{

System.Web.UI.WebControls.Table Tab =new System.Web.UI.WebControls.Table();

Tab.BorderWidth =newUnit(3);

Tab.BorderColor = System.Drawing.Color.AliceBlue;

Tab.CellPadding = 1;

//Tab.CellSpacing = 1;

TableRow Tr =newTableRow();

TableCell Tc1 =newTableCell();

TableCell Tc2 =newTableCell();

TableCell Tc3 =newTableCell();

TableCell Tc4 =newTableCell();

Label label4 =newLabel();

label4.ID ="label4";

label4.Text ="Employee ID";

Tc4.Controls.Add(label4);

Tr.Cells.Add(Tc4);

Label label1 =newLabel();

label1.ID ="label1";

label1.Text ="Employee";

Tc1.Controls.Add(label1);

Tr.Cells.Add(Tc1);

Label label2 =newLabel();

label2.ID ="label2";

label2.Text ="Attendance";

Tc2.Controls.Add(label2);

Tr.Cells.Add(Tc2);

Label label3 =newLabel();

label3.ID ="label3";

label3.Text ="Remark";

Tc3.Controls.Add(label3);

Tr.Cells.Add(Tc3);

Tab.Rows.Add(Tr);

Tr.BackColor = System.Drawing.Color.AliceBlue;

EmployeeList =EmployeeReg.SelectStaff();

EmployeeReg empreg;

EmployeeNo = EmployeeList.Count;

Empid =newLabel[EmployeeList.Count];

Empname =newLabel[EmployeeList.Count];

Attendance =newRadioButtonList[EmployeeList.Count];

Remark =newTextBox[EmployeeList.Count];

for (int i = 0; i < EmployeeList.Count; i++)

{

empreg =newEmployeeReg();

empreg = EmployeeList[i];

//initialize table row

Tr =newTableRow();

//initialize columns in particular row

Tc1 =newTableCell();

Tc2 =newTableCell();

Tc3 =newTableCell();

Tc4 =newTableCell();

//Generating Employee ID in table.

Label Lbl2 =newLabel();

Lbl2.ID ="lblEmpid" + i.ToString();

Lbl2.BackColor= System.Drawing.Color.AliceBlue;

Lbl2.Text = empreg.EmployeeID.ToString();

Empid[i] = Lbl2;

Tc4.Controls.Add(Lbl2);

Tr.Cells.Add(Tc4);

//Generating Employee name in table.

Label Lbl1 =newLabel();

Lbl1.ID ="lblName" + i.ToString();

Lbl1.Text = empreg.EmployeeName.ToString();

Empname[i] = Lbl1;

Tc1.Controls.Add(Lbl1);

Tr.Cells.Add(Tc1);

//Genertaing radiobuttonlist for attendance

RadioButtonList rdbl =newRadioButtonList();

rdbl.ID ="rdblAtt" + i.ToString();

rdbl.RepeatDirection =RepeatDirection.Horizontal;

ListItem item1 =newListItem();

//item1.Text = "Present";

item1.Value ="P";

item1.Selected =true;

rdbl.Items.Add(item1);

ListItem item2 =newListItem();

// item2.Text = "Absent";

item2.Value ="A";

rdbl.Items.Add(item2);

ListItem item3 =newListItem();

// item3.Text = "Off Day";

item3.Value ="O";

rdbl.Items.Add(item3);

ListItem item4 =newListItem();

// item4.Text = "Half Day";

item4.Value ="H";

rdbl.Items.Add(item4);

Attendance[i] = rdbl;

Tc2.Controls.Add(rdbl);

Tr.Cells.Add(Tc2);

//Genertaing TextBox for Remark

TextBox Txt1 =newTextBox();

// Txt1.ID = "txtRemark" + i.ToString();

Remark[i] = Txt1;

Remark[i].ID ="txtRemark" + i.ToString();

Remark[i].Text ="";

Tc3.Controls.Add(Txt1);

Tr.Cells.Add(Tc3);

Tab.Rows.Add(Tr);

}

this.Panel1.Controls.Add(Tab);

}

0 comments:

Post a Comment