473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dynamic adding rows into table problem

Hello

I wrote a program with code behind in C# to add row into table
dynamically and the program worked very well in .Net Framework 1.1. When I
run this program in .Net Framework 2.0 beta version, the program is not
working as in version 1.1. So what is the problem? Microsoft declared that
the version 2.0 is fully backward support, but it is not. Is that the
problem with 2.0 version?

I find out the problem in version 2.0. After adding rows into table, I
saved the table in to Session variable Session["main_table"]. When the page
posts back, I retrieved the table from
main_table = (Table) Session["main_table"]. In version 1.1 it worked well,
but in version 2.0, I could save the table after dynamically adding rows,
but when I retrieved the table on post back, I got and empty table with no
rows in it. Please help, any resource link is appreciated. Below is the
program.
Sorry for the long code.
============
TableTest.aspx
============

<%@ Page Language="C#" Inherits="WebControlTest"%>

<html>
<head>
<title> Test </title>
</head>
<body>

<form id="test_form" runat="server">
<asp:PlaceHolder runat="server" id="holdtable" />
<br>
<asp:Button id="add_button" text="Add Row" OnClick="CreateRow"
runat="server"/>
&nbsp;<asp:Button id="delete_button" text="Delete" OnClick="DeteleRow"
runat="server"/>
&nbsp;<asp:Button id="submit_button" text="Submit" OnClick="Submit_Click"
runat="server"/>
<br><asp:Label id="label" runat="server"/>

</form>
</body>
</html>

========================================
WebControlTest.cs
========================================
using System;
using System.Web.UI;
using System.Web.UI.WebControls;

public class WebControlTest : System.Web.UI.Page
{
Table main_table;
int num_row = 0;

protected Label label;
protected PlaceHolder holdtable;
protected Button delete_button;
protected Button submit_button;
TextBox text = new TextBox();
protected override void OnInit(EventArgs e) {

main_table = (Table)Session["table"];

if(main_table == null){
main_table = new Table();
main_table.BorderWidth = 1;
main_table.GridLines = (GridLines)3;
}
}
protected void Page_Load(object sender, System.EventArgs e)
{
label.Text = "";
holdtable.Controls.Add(main_table);

if(!Page.IsPostBack){
Response.Write("New Request<br>");
}
else{
Response.Write("Page Post Back<br>");
}
}

protected void CreateRow(object sender, System.EventArgs e){

num_row = (main_table.Rows).Count;

TableRow r = new TableRow();
TableCell c1 = new TableCell();
TableCell c2 = new TableCell();
TextBox t = new TextBox();

t.ID = "textID" + num_row;
t.EnableViewState = true;

r.ID="newRow" + num_row;
c1.ID="newC1" + num_row;
c2.ID="newC2" + num_row;

c1.Text = "New Cell - " + num_row;
c2.Controls.Add(t);

r.Cells.Add(c1);
r.Cells.Add(c2);

main_table.Rows.Add(r);
Session["table"] = main_table;
}
protected void DeteleRow(object sender, System.EventArgs e)
{
main_table = (Table)Session["table"];
num_row = (main_table.Rows).Count;

if(num_row > 0) {
TableRow remove = main_table.Rows[num_row - 1];
main_table.Rows.Remove(remove);
}
Session["table"] = main_table;
}

protected void Submit_Click(object sender, System.EventArgs e){
num_row = (main_table.Rows).Count;

label.Text = "";

for(int i = 0; i < num_row; i++){
text = (TextBox)holdtable.FindControl("textID" + i);

if(text != null){
label.Text += "textID" + i + " = " + text.Text + "<br>";
}
}
}
}
Nov 19 '05 #1
0 2382

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Sue | last post by:
On code-behind page: (attributes set programatically for each of these elements) linkbutton added to tablecell textbox added to tablecell tablecells added to tablerow tablerow added to table...
7
by: David Findlay | last post by:
I'm trying to do a table for laying out a links page in CSS. See http://qldstorms.com/links.php. My stylesheet is at http://qldstorms.com/styles/screen.css. My problem is that if the link name in...
2
by: Clayton Hamilton | last post by:
I have a DataGrid on a webform bound to a Datasource and can successfully use <ItemTemplate> to create edit/update/cancel functionality for user maintenance of data. I use separate logic to delete...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
0
by: Sileesh | last post by:
Hi I have html table and a Button in an Aspx page. I am adding one row with some textboxes to Html table each time i click on the Button thru Javascript. Now problem is when when i try to...
4
by: VMI | last post by:
I'm working on a questionaire, and I'd like to add the questions to a gridview, so that each row (of two "columns" each) has the question in one field, and the editable section (where the user will...
5
by: viperdriver87 | last post by:
Greetings all, I had another post on here about a Dynamic array of ints problem, and with your help, I managed to solve that problem. Now, I've another issue. I need to dyanically allocate an array...
0
by: ganesh22 | last post by:
Hi... Iam using GridView in asp.net(2.0) .My requirement is user can add,update,delete in gridview I written the code for add & update but can u help adding rows in grid view My code: ...
3
by: josephamarks | last post by:
I am trying to correct a table problem. In IE6, the table (created in VS with ASPX) does display correctly. Ijn IE8, it adds unwanted horizontal scrollbars, and the columns do not display...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.