Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

Dynamically adding rows to table web server control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Geary - 24 Jul 2007 20:26 GMT
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
bruce barker - 24 Jul 2007 20:37 GMT
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)

> 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
[quoted text clipped - 33 lines]
>
>     End Sub
Geary - 26 Jul 2007 14:03 GMT
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?

> your code needs to remember the rows it added on the last click, and
> re-add them on the postback (say in oninit).
[quoted text clipped - 38 lines]
>>
>>     End Sub

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.