I'd get away from building the HTML table manually.
I'd store the info in a datatable and bind the table to a grid (or
repeater). When legs are added, they get added to the datatable which
you can store in a session variable or database, and simply rebind the
grid to the updated table. This would cut out 90% of your code.
On 11/17/05, shawnarnwine <[EMAIL PROTECTED]> wrote:
> I've gotten a lot of useful information from everyone here, but I'm
> just short of going insane with the problem I am experiencing.
>
> I have 2 aspx pages. On page 1 (Trip.aspx) there are 2 links
> buttons, one for new Trip, one for Existing Trip.
> If the user clicks New, I append "new" to the querystring and move
> to page 2 (TripNewEdit.aspx)
> If the user clicks Existing, I display a table with existing trip
> information from which the user selects a trip. I then
> append "edit" to the querystring and move to page 2
> (TripNewEdit.aspx) which I populate the appropriate textboxes.
>
> Now, aside from the usual textbox entered data, each trip can
> have "n" trip legs (ie.-from Baltimore to DC, DC to San Fran...).
> The trip legs are in a server table which is displayed on
> TripNewEdit.aspx. If its a new trip, I dynamically
> create 2 legs (row) in the table...if its an existing trip, I
> display the number of current legs. Within the trip leg table is a
> link button to "Add" additional leg rows to the table.
> This calls the LegAddLink_Click event, which adds a new row
> appending the row number to the control name creating a unique ID.
>
> The problem I am experiencing is that whenever I generate additional
> legs to the table, I have to regenerate all (existing & new) of the
> leg rows each time the page loads.
>
> Is there a way around this? I'm having a hard time determining what
> I need to use Viewstate on, and/or if I can just apply it to the
> table as a whole. It just seems like a lot of work to keep objects
> persisted. Then again, I'm sure I'm wrong.
>
> Here is my pseudo code:
>
> Sub Page_Init()
> If Querystring = "new" Then
> LoadNewTripTable()
> Elseif Querystring = "edit" then
> LoadExistingTable()
> End If
>
> End Sub
>
> Sub Page_Load()
> 'Nothing
> End Sub
>
> Sub LoadNewTable()
> 'build initial 2 leg rows
> for row = 1 to 2
> BuildLegTable(row)
> Next
>
> ViewState("mode") = "new"
> End Sub
>
> Sub LoadExistingTable()
> 'Populate existing text boxes
>
> 'build leg rows based on legs
> for each row in triplegs
> BuildLegTable(row)
> Next
>
> ViewState("mode") = "edit"
> End Sub
>
> Function BuildLegTable(row)
>
> Dim tRow as NEw TableRow
> For cellCtr = 1 to 8 'there are 8 cells per row
> Dim tCell as New TableCell
> Select Case cellCtr
> ...
> newControl.id = "Name" & rowCtr
> tCell.Controls.Add(newControl)
> End Select
> tRow.Cells.Add(tCell)
> Next
> Table.Rows.Add(tRow)
> End Function
>
> Sub LegAddLink_Click()
> Dim passThruCnt As Boolean ' used to check to see if on a
> new record this is the first time thru so that we know to start with
> row #3
>
> If Page.IsPostBack Then
>
> If Viewstate("mode") = "new" And ViewState("passThruCnt") =
> False Then
> rowBegin = 3 'first time around, begin & end with
> row #3
> rowEnd = 3
> Elseif Viewstate("mode") = "new" And ViewState
> ("passThruCnt") = True Then
> rowBegin = 3 'have to begin with row #3 again in
> order to properly regenerate the new rows.
> rowEnd = ViewState("rowCnt") ' contains the total
> number of rows after new row was added (see below)
> Elseif Viewstate("mode") = "edit" And ViewState
> ("passThruCnt") = False Then
> 'rowBegin = 'haven't gotten this far yet
> 'rowEnd = '
> End if
>
> for row = rowBegin to rowEnd
> BuildLegTable(rowCtr)
> next
>
> Viewstate("rowCnt") = Leg.Rows.Count 'gets new count of
> table rows
> Viewstate("passThruCnt") = True
> End Sub
>
> '*********
> Any and all help is greatly appreciated. Thanks!
>
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
--
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com
------------------------ Yahoo! Groups Sponsor --------------------~-->
Get fast access to your favorite Yahoo! Groups. Make Yahoo! your home page
http://us.click.yahoo.com/dpRU5A/wUILAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/