473,404 Members | 2,114 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,404 software developers and data experts.

Dynamically adding rows to table web server control

I am trying to programmatically add rows of data to a table web control
in VS2005. I am getting the data from 2 drop-down controls and 2
text-boxes. The code below is executed when I click on the "add"
button. The code is pretty much lifted from an example on MSDN.

Problem:

The first time I try to add a row, it works fine. But when I try to add
another row, it simply overwrites the first. I need to add new row
every time the user clicks the 'add' button.

--------------------------------

Protected Sub btnProdAdd_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnProdAdd.Click

Dim tr As New TableRow()

Dim cellGrade As New TableCell()
cellGrade.Text = cboGrade.SelectedValue.ToString
tr.Cells.Add(cellGrade)

Dim cellStrips As New TableCell()
cellStrips.Text = cboStrips.SelectedValue.ToString
tr.Cells.Add(cellStrips)

Dim cellYards As New TableCell()
cellYards.Text = txtYards.Text.ToString
tr.Cells.Add(cellYards)

Dim cellScrap As New TableCell()
cellScrap.Text = txtScrap.Text.ToString
tr.Cells.Add(cellScrap)

tblProd.Rows.Add(tr)
End Sub
Jul 24 '07 #1
2 2491
your code needs to remember the rows it added on the last click, and
re-add them on the postback (say in oninit).

-- bruce (sqlwork.com)

Geary wrote:
I am trying to programmatically add rows of data to a table web control
in VS2005. I am getting the data from 2 drop-down controls and 2
text-boxes. The code below is executed when I click on the "add"
button. The code is pretty much lifted from an example on MSDN.

Problem:

The first time I try to add a row, it works fine. But when I try to add
another row, it simply overwrites the first. I need to add new row
every time the user clicks the 'add' button.

--------------------------------

Protected Sub btnProdAdd_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnProdAdd.Click

Dim tr As New TableRow()

Dim cellGrade As New TableCell()
cellGrade.Text = cboGrade.SelectedValue.ToString
tr.Cells.Add(cellGrade)

Dim cellStrips As New TableCell()
cellStrips.Text = cboStrips.SelectedValue.ToString
tr.Cells.Add(cellStrips)

Dim cellYards As New TableCell()
cellYards.Text = txtYards.Text.ToString
tr.Cells.Add(cellYards)

Dim cellScrap As New TableCell()
cellScrap.Text = txtScrap.Text.ToString
tr.Cells.Add(cellScrap)

tblProd.Rows.Add(tr)
End Sub
Jul 24 '07 #2
If I am understanding you correctly, you are saying that every time the
user triggers the code to add a new record to the table control, the
code has to re-add all of the existing records already in the table in
addition to the new one?

And this would be because of the statelessness of web apps?

bruce barker wrote:
your code needs to remember the rows it added on the last click, and
re-add them on the postback (say in oninit).

-- bruce (sqlwork.com)

Geary wrote:
>I am trying to programmatically add rows of data to a table web
control in VS2005. I am getting the data from 2 drop-down controls
and 2 text-boxes. The code below is executed when I click on the
"add" button. The code is pretty much lifted from an example on MSDN.

Problem:

The first time I try to add a row, it works fine. But when I try to
add another row, it simply overwrites the first. I need to add new
row every time the user clicks the 'add' button.

--------------------------------

Protected Sub btnProdAdd_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnProdAdd.Click

Dim tr As New TableRow()

Dim cellGrade As New TableCell()
cellGrade.Text = cboGrade.SelectedValue.ToString
tr.Cells.Add(cellGrade)

Dim cellStrips As New TableCell()
cellStrips.Text = cboStrips.SelectedValue.ToString
tr.Cells.Add(cellStrips)

Dim cellYards As New TableCell()
cellYards.Text = txtYards.Text.ToString
tr.Cells.Add(cellYards)

Dim cellScrap As New TableCell()
cellScrap.Text = txtScrap.Text.ToString
tr.Cells.Add(cellScrap)

tblProd.Rows.Add(tr)
End Sub
Jul 26 '07 #3

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

Similar topics

4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
0
by: sameer mowade via .NET 247 | last post by:
Hello All, I have problem while dynamically removing row from the Datagrid which i have added dynamically as shown in the following code snippet. The problem is that while removing dynamically...
1
by: Paul | last post by:
HI I have a asp page which dynamically creates a table with 28 rows, 3 columns. Column 1 contains a label, column 2 contains a graphic, column 3 needs to contain a checkbox. I have no problems...
4
by: Rob Meade | last post by:
Hi all, I'm desperately trying to get this to work and I just cant do it - new to ASP.net - probably the reason! I'm using visual studio for this - I have this in the html page : <asp:Table...
2
by: buran | last post by:
Dear ASP.NET Programmers, I have a HTML table (running as server control with the control ID: tblInsertSP). The table has 16 rows with textboxes. Depending on the value of the ddlSPType, which...
2
by: Chad | last post by:
I have a problem that I am desperate to understand. It involves dynamically adding controls to a Table control that is built as a result of performing a database query. I am not looking to...
8
by: utterberg | last post by:
Hi I'm adding two dropdownlist in my webform by clicking a button. I fill the first dropdown with some values from my DB and the other one when I choose from the first dropdown. But since theese...
4
by: Lewis Holmes | last post by:
Hi I have the following situation in one of my asp.net pages. The user can add multiple table rows to a form by selecting a button. These rows can contain asp.net controls. When this button is...
7
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I'm adding subheadings to a gridview. Each sub head has a few link buttons. I'm adding the controls in the rowdatabound event code follows: sorry about the length here. I have to be missing...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
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.