Mayank_Agarwal
asked on
Dynamic table row with viewstate
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(earli erState)
'If Not ViewState("TableRow") Is Nothing Then
If ViewState("TableRow") = True Then
createTable()
End If
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(earli
'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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
can you paste the button click event code...
Anurag
Anurag
ASKER
Protected Overrides Sub LoadViewState(ByVal earlierState As Object)
MyBase.LoadViewState(earli erState)
If ViewState("vwPlanRow") = True Then
createPlan()
'ViewState("vwDashRow") = False
End If
If ViewState("vwDashRow") = True Then
createDash()
'MyBase.LoadViewState(earl ierState)
'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
MyBase.LoadViewState(earli
If ViewState("vwPlanRow") = True Then
createPlan()
'ViewState("vwDashRow") = False
End If
If ViewState("vwDashRow") = True Then
createDash()
'MyBase.LoadViewState(earl
'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
Why you have repeated code of creating Dash & Plan in LoadViewState function. When you are creating the tables on button click.
Anurag
Anurag
ASKER
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?
Protected Overrides Sub LoadViewState(ByVal earlierState As Object)
MyBase.LoadViewState(earli erState)
If ViewState("vwPlanRow") = True Then
createPlan()
'ViewState("vwDashRow") = False
End If
If ViewState("vwDashRow") = True Then
createDash()
'MyBase.LoadViewState(earl ierState)
'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
MyBase.LoadViewState(earli
If ViewState("vwPlanRow") = True Then
createPlan()
'ViewState("vwDashRow") = False
End If
If ViewState("vwDashRow") = True Then
createDash()
'MyBase.LoadViewState(earl
'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
ASKER
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
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
ASKER
none of the above are suitable solutions
Anurag