473,840 Members | 1,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="WebCo ntrolTest"%>

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

<form id="test_form" runat="server">
<asp:PlaceHolde r runat="server" id="holdtable" />
<br>
<asp:Button id="add_button " text="Add Row" OnClick="Create Row"
runat="server"/>
&nbsp;<asp:Butt on id="delete_butt on" text="Delete" OnClick="Detele Row"
runat="server"/>
&nbsp;<asp:Butt on id="submit_butt on" text="Submit" OnClick="Submit _Click"
runat="server"/>
<br><asp:Labe l id="label" runat="server"/>

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

=============== =============== ==========
WebControlTest. cs
=============== =============== ==========
using System;
using System.Web.UI;
using System.Web.UI.W ebControls;

public class WebControlTest : System.Web.UI.P age
{
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(EventArg s e) {

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

if(main_table == null){
main_table = new Table();
main_table.Bord erWidth = 1;
main_table.Grid Lines = (GridLines)3;
}
}
protected void Page_Load(objec t sender, System.EventArg s e)
{
label.Text = "";
holdtable.Contr ols.Add(main_ta ble);

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

protected void CreateRow(objec t sender, System.EventArg s e){

num_row = (main_table.Row s).Count;

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

t.ID = "textID" + num_row;
t.EnableViewSta te = 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(objec t sender, System.EventArg s e)
{
main_table = (Table)Session["table"];
num_row = (main_table.Row s).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(ob ject sender, System.EventArg s e){
num_row = (main_table.Row s).Count;

label.Text = "";

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

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

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

Similar topics

5
5294
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 (table.ID is TestTable) On .aspx page: <HeaderTemplate> <asp:Table ID="TestTable" runat="Server" /> </HeaderTemplate>
7
1873
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 the first column get's word wrapped, but the description text in the second column doesn't, the next row get's wrapped to sit next second line of the link name. Also if a two line link name is last in the category box, it'll cross the outside of...
2
3644
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 a row. Everything works just fine. BUT I would like to add a button to (for example) the DataGrid header, which when pressed will add a new row to the datagrid. This should then allow the user to enter information into text boxes (in some...
3
4891
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 the best method? Do you have a sample of how to do this?
0
1883
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 collect the data in the Textboxes which i added dynamically from server side, i am not able to do . Alos i tried to bedug, the total no of rows in Html table does not reflect the dynamically added rows.
4
8752
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 enter the answer) in the next field. The questions are not stored in a table, and I'm thinking of saving the answers manually (i.e. no datasource). Is this possible? This is a web app using asp.net 2.0. THanks.
5
2708
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 of structs. The struct is defined as: struct song{ char name; char title; };
0
1970
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: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3" Height="237px" Style="z-index: 100; left: 155px; position: absolute; top: 132px" Width="688px" BackColor="White" BorderColor="#CCCCCC"...
3
3051
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 properly -- they are too spread out without the horizontal scrollbars. Is there any way to restrain the columns so that the horizontal scrollbars are not needed. I know how to set overflow to hidden so that the horizontal scrollbars do not appear;...
0
9856
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10916
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10657
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10299
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9436
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5684
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4071
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3136
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.