Help adding Table Rows dynamically Please! 
Author Message
 Help adding Table Rows dynamically Please!

I need to add table rows dynamically that contain
textboxes on a webform -- i have a button to "Add
Sessions" and when the button is clicked it does add 1
row, but when i go to add another, it either doesn't do
anything or it just replaces the 1st added row --

I guess my question is how would I continue to add table
rows when the "add" button is clicked?

Any help would be much appreciated!



Mon, 14 Feb 2005 05:30:14 GMT  
 Help adding Table Rows dynamically Please!
You need to store the # of rows and re-setup the table with the correct # of
rows each time when the button is pressed:

Here's a sample snipit using a DataSet as the storage mechanism - I then
bound it to a datagrid:
1) I created a blank webform and added  a Button (Button1) and a DataGrid
(DataGrid1):
2) Add the following Code:
  Public dt As New DataSet
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        If Not IsPostBack Then
            ' First time in I need to Create the DataSet with the correct #
of columns, and correct datatypes for each column.
            dt = New DataSet
            dt.Tables.Add("MyTable")
            dt.Tables(0).Columns.Add("C1",
System.Type.GetType("System.String"))
            Session("MYTABLE") = dt
        Else
            dt = Session("MYTABLE")
        End If

        ' Bind the DataGrid to the table
        Me.DataGrid1.DataSource = dt
        DataGrid1.DataBind()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        ' Retrieve the DataSet
        dt = Session("MYTABLE")

        ' Add a Row to the table.
        Dim c(0) As String
        c(0) = "Row # " & dt.Tables(0).Rows.Count + 1
        dt.Tables(0).Rows.Add(c)

        ' Save the state & Re-Bind.
        Session("MYTABLE") = dt
        Me.DataGrid1.DataSource = dt
        DataGrid1.DataBind()

    End Sub

Thanks
GarySp & JonBraz
--
This posting is provided "AS IS" with no
warranties, and confers no rights.

Please do not send email directly to
this alias. This alias is for newsgroup
purposes only.

Quote:
> I need to add table rows dynamically that contain
> textboxes on a webform -- i have a button to "Add
> Sessions" and when the button is clicked it does add 1
> row, but when i go to add another, it either doesn't do
> anything or it just replaces the 1st added row --

> I guess my question is how would I continue to add table
> rows when the "add" button is clicked?

> Any help would be much appreciated!



Sun, 20 Feb 2005 03:49:05 GMT  
 Help adding Table Rows dynamically Please!
Thanks -- You Da' Man!(Men!)

Quote:
>-----Original Message-----
>You need to store the # of rows and re-setup the table

with the correct # of
Quote:
>rows each time when the button is pressed:

>Here's a sample snipit using a DataSet as the storage
mechanism - I then
>bound it to a datagrid:
>1) I created a blank webform and added  a Button

(Button1) and a DataGrid
Quote:
>(DataGrid1):
>2) Add the following Code:
>  Public dt As New DataSet
>    Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As
>System.EventArgs) Handles MyBase.Load
>        'Put user code to initialize the page here
>        If Not IsPostBack Then
>            ' First time in I need to Create the DataSet
with the correct #
>of columns, and correct datatypes for each column.
>            dt = New DataSet
>            dt.Tables.Add("MyTable")
>            dt.Tables(0).Columns.Add("C1",
>System.Type.GetType("System.String"))
>            Session("MYTABLE") = dt
>        Else
>            dt = Session("MYTABLE")
>        End If

>        ' Bind the DataGrid to the table
>        Me.DataGrid1.DataSource = dt
>        DataGrid1.DataBind()

>    End Sub

>    Private Sub Button1_Click(ByVal sender As

System.Object, ByVal e As

- Show quoted text -

Quote:
>System.EventArgs) Handles Button1.Click
>        ' Retrieve the DataSet
>        dt = Session("MYTABLE")

>        ' Add a Row to the table.
>        Dim c(0) As String
>        c(0) = "Row # " & dt.Tables(0).Rows.Count + 1
>        dt.Tables(0).Rows.Add(c)

>        ' Save the state & Re-Bind.
>        Session("MYTABLE") = dt
>        Me.DataGrid1.DataSource = dt
>        DataGrid1.DataBind()

>    End Sub

>Thanks
>GarySp & JonBraz
>--
>This posting is provided "AS IS" with no
>warranties, and confers no rights.

>Please do not send email directly to
>this alias. This alias is for newsgroup
>purposes only.


>> I need to add table rows dynamically that contain
>> textboxes on a webform -- i have a button to "Add
>> Sessions" and when the button is clicked it does add 1
>> row, but when i go to add another, it either doesn't do
>> anything or it just replaces the 1st added row --

>> I guess my question is how would I continue to add
table
>> rows when the "add" button is clicked?

>> Any help would be much appreciated!

>.



Sun, 20 Feb 2005 12:26:09 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. to add row dynamically in table

2. Add new row to a table dynamically

3. adding a table row, without setting same defaults as previous row

4. row heights of table rows added by vba

5. need help please:joined tables,add new entries based on one table columns

6. need help please:joined tables,add new entries based on one table columns

7. Adding and deleting columns dynamically, repeating row headers

8. Problem with dynamically created HTML table rows

9. PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP,

10. Problem dynamically adding fields to tables

11. Dynamically adding tables?

12. Crystal Reports: add/delete groups dynamically and starting a new page dynamically

 

 
Powered by phpBB® Forum Software