How to add the data present in the controls to a table control without any database involvement.


Hi All,i am four controls where i will write the text and once i click the add button those should get added to the table .i want 6 columns fixed in the table and rows as many as required.i tried doing that taking a table server control and able to load the table.but the problem is whenver i am adding a new row the old one is gfetting overwritten by this and at the end i am getting only one row. 
System.Web.UI.WebControls.Table t1 = new System.Web.UI.WebControls.Table();
 i have declared the below one global
TableRow tr; TableCell tc1; TableCell tc2; TableCell tc3;
in page load i have written
t1.EnableViewState=true;
Session["Table"]=t1;
 in the add button click i have writtentr = new TableRow();
tc1 = new TableCell();
tc2 = new TableCell();
tc3= new TableCell();
if(Session["Table"].ToString()=="")
{
 
t1.Rows.Add(tr);
 
tc1.Text = "ProjectId";
tc1.BorderWidth=1;
tr.Cells.Add(tc1);
 
 
tc2.Text ="ProjectName";
tc2.BorderWidth=1;
tr.Cells.Add(tc2);
 
tc3.Text= "Name Changed";
tc3.BorderWidth=1;
tr.Cells.Add(tc3);
PlaceHolder1.Controls.Add(t1);
}
else
{
t1=Session["Table"];
tc1.Text="yemo";
tc2.Text="Hello";
tc3.Text="hi";
tr.Cells.Add(tc1);
tr.Cells.Add(tc2);
tr.Cells.Add(tc3);
t1.Rows.Add(tr);
Session["Table"]=t1;
PlaceHolder1.Controls.Add(t1);
but its not working at all.Kindly help me..
 
0
chaitanya_chakkilam
8/23/2007 2:21:26 PM
📁 asp.net.web-forms
📃 93655 articles.
⭐ 6 followers.

💬 1 Replies
👁️‍🗨️ 1610 Views



Hi chaitanya_chakkilam,
 
Based on my understanding, you can use t1 = (Table)Session["Table"]; instead of <strike>t1=Session["Table"];</strike> to solve your problem.

Please correct me if I have misunderstood your mean, please LET ME KNOW. Thanks,

Hope it helps,
Hong Gang

Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Hong
8/28/2007 1:53:55 PM
Reply: