Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dynamic table row with viewstate

Posted on 2008-06-19
9
Medium Priority
?
1,513 Views
Last Modified: 2008-08-02
hello hello!

I am trying to create a table which will have dynmic additions to rows, the cells in the row will have textboxes as well.
Then the user clicks on "Add new Row" the row gets added to exisitng table. The key is that the information typed in previous rows should not disappear.
There is  "SAVE" button in the form as well. when the user clicks on this button the data in each row should be inserted in the database  one by one. Thus the Row should accessed programitically.


I have the below code called at LinkButton Click and
    Protected Overrides Sub LoadViewState(ByVal earlierState As Object)
        MyBase.LoadViewState(earlierState)
        'If Not ViewState("TableRow") Is Nothing Then
        If ViewState("TableRow") = True Then
            createTable()
        End If
Public Sub createMyTable()
        Dim rowCtr As Integer
        Dim cellCtr As Integer
        Dim t As TextBox
        Dim rowCnt As Integer = tblDashboard.Rows.Count
        If rowCnt < Session("NewCntRow") Then
            rowCnt = Session("NewCntRow")
        End If
 
        For rowCtr = 1 To rowCnt
            Dim tRow As New TableRow
            tRow.Height = 50
            Me.tblDashboard.Rows.Add(tRow)
            Session("NewCntRow") = tblDashboard.Rows.Count
            For cellCtr = 0 To tblDashboard.Rows(0).Cells.Count - 1
                t = New TextBox
                't.EnableViewState = True
                't.ID = "txt" & cellCtr
                Dim tCell As New TableCell
                tRow.Cells.Add(tCell)
                tRow.Cells.Item(cellCtr).Controls.Add(t)
            Next
            ViewState("TableRow") = True
        Next
 
    End Sub

Open in new window

0
Comment
Question by:Mayank_Agarwal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 11

Expert Comment

by:Anurag Agarwal
ID: 21829065
What is the problem Statement?

Anurag
0
 
LVL 1

Accepted Solution

by:
Mayank_Agarwal earned 0 total points
ID: 21843249
Hi
There are two tables on the page. Using the View state I ma able to keep the information on the page, But when i click on the any of the buttons the table is created for botht he table rather then only one of them,
0
 
LVL 11

Expert Comment

by:Anurag Agarwal
ID: 21843406
can you paste the button click event code...

Anurag
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:Mayank_Agarwal
ID: 21844173
   Protected Overrides Sub LoadViewState(ByVal earlierState As Object)
        MyBase.LoadViewState(earlierState)

        If ViewState("vwPlanRow") = True Then
            createPlan()
            'ViewState("vwDashRow") = False
        End If

        If ViewState("vwDashRow") = True Then
            createDash()
            'MyBase.LoadViewState(earlierState)
            'ViewState("vwPlanRow") = False
        End If

    End Sub


Then CreatePlan and CreateDash sub creates table row straightforward stuff.

Linkbutton events
    Protected Sub lnkPlan_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not ViewState("vwPlanRow") = True Then
            createPlan()
        End If

    End Sub

    Protected Sub lnkDash_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkDash.Click
        If Not ViewState("vwDashRow") = True Then
            createDash()
        End If
    End Sub


0
 
LVL 11

Expert Comment

by:Anurag Agarwal
ID: 21845021
Why you have repeated code of creating Dash & Plan in LoadViewState function. When you are creating the tables on button click.

Anurag
0
 
LVL 1

Author Comment

by:Mayank_Agarwal
ID: 21851137
I thought i have to do this to recreate the table with orignal value in them? is there are a better way of doing this?
0
 
LVL 11

Expert Comment

by:Anurag Agarwal
ID: 21852407
Protected Overrides Sub LoadViewState(ByVal earlierState As Object)
        MyBase.LoadViewState(earlierState)

        If ViewState("vwPlanRow") = True Then
            createPlan()
            'ViewState("vwDashRow") = False
        End If

        If ViewState("vwDashRow") = True Then
            createDash()
            'MyBase.LoadViewState(earlierState)
            'ViewState("vwPlanRow") = False
        End If

    End Sub


In the above function you are calling same methods createPlan & createDash, rest of the code is commented, how you are loading the old state in this?

I feel this will create both the tables. To retain the original values you can try doing the viewstate of tblDashboard as true & comment all code in LoadViewState().

Anurag
0
 
LVL 1

Author Comment

by:Mayank_Agarwal
ID: 21852465
there are two tables that why i had to use this otherwise it only creates one table and clears teh second table.

Is there any other way to achieve this., i needt o two table either datagrid,gridview, table who care
the user should be able to add the data one by one (dynamic row generation) and than click on SAVE button to save complete data on the form
0
 
LVL 1

Author Comment

by:Mayank_Agarwal
ID: 22022763
none of the above are suitable solutions
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question