473,320 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

TableRows and Postback

I've been at this all day and it's really starting to annoy me now. I have a
form, this has a textbox which the user enters a search parameter into. This
is passed to a Stored Procedure as a parameter, the results returned are then
bound to a GridView control. This GridView control has an extra column with a
checkbox in it for every row. The idea for this being that the user selects
which items he/she would like to use by checking the checkboxes.

Once they have made their selection, they then click a button and this
copies their selections over to an ASP:Table control. The table control is
declaratively created with each table row being dynamically created.

All of the above works fine using the code included in this post. The
problems begin if they then start another search, they want to keep the
values in the table but the table is cleared and populated with the new
values when they add the results of their new search to it.

STEP: User performs a search.
RESULT: GridView populated with results of search

STEP: User selects items they want to use from the GridView and then click
on the Add To List button.
RESULT: Table control has x amount of rows added containing the details as
they appear in the GridView.

STEP: User then selects more items from the same search.
RESULT: The items selected are appended to the table.

STEP: User performs another search and selects the items from those search
results.
RESULT: Table only shows the items that the user has just selected, all the
previous items are lost
I've taken a screenshot of the test form to help you visualize it.
(http://mparter.pwp.blueyonder.co.uk/dyntable.png)

Please save me before I go mad

Thanks.

------------------------------------------CODE------------------------------------------------

Protected Sub AddToList()
Dim gridRow As GridViewRow

For Each gridRow In GridView1.Rows

Dim gridCell0 As TableCell = gridRow.Cells(0)
Dim gridCell1 As TableCell = gridRow.Cells(1)
Dim gridCell2 As TableCell = gridRow.Cells(2)
Dim gridCell3 As TableCell = gridRow.Cells(3)
Dim gridCell4 As TableCell = gridRow.Cells(4)

Dim chkStudent As HtmlInputCheckBox =
CType(gridCell0.Controls(1), HtmlInputCheckBox)
If Not (chkStudent Is Nothing) And chkStudent.Checked Then
Dim tblRow As New TableRow
Dim tblCell0 As New TableCell
Dim tblCell1 As New TableCell
Dim tblCell2 As New TableCell
Dim tblCell3 As New TableCell
Dim tblCell4 As New TableCell

Dim chkSelectedStudent As New HtmlInputCheckBox

tblCell0.Controls.Add(chkSelectedStudent)
chkSelectedStudent.ID = "chkSelectedStudent_" & gridCell1.Text
chkSelectedStudent.Value = gridCell1.Text
tblRow.Cells.Add(tblCell0)
tblCell1.Controls.Add(New LiteralControl(gridCell1.Text))
tblRow.Cells.Add(tblCell1)
tblCell2.Controls.Add(New LiteralControl(gridCell2.Text))
tblRow.Cells.Add(tblCell2)
tblCell3.Controls.Add(New LiteralControl(gridCell3.Text))
tblRow.Cells.Add(tblCell3)
tblCell4.Controls.Add(New LiteralControl(gridCell4.Text))
tblRow.Cells.Add(tblCell4)

Table1.Rows.Add(tblRow)
End If
Next
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Label1.Text = DateTime.Now.ToString
If Page.IsPostBack Then
AddToList()
End If
End Sub
Nov 19 '05 #1
2 1549
I think you need to create a session variable to contain the selected rows
(i.e. Session("AddedItemsTable")=AddedItemsTable, that way previous
selections will be remembered between postbacks.
"Mark Parter" <Ma********@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
I've been at this all day and it's really starting to annoy me now. I have
a
form, this has a textbox which the user enters a search parameter into.
This
is passed to a Stored Procedure as a parameter, the results returned are
then
bound to a GridView control. This GridView control has an extra column
with a
checkbox in it for every row. The idea for this being that the user
selects
which items he/she would like to use by checking the checkboxes.

Once they have made their selection, they then click a button and this
copies their selections over to an ASP:Table control. The table control is
declaratively created with each table row being dynamically created.

All of the above works fine using the code included in this post. The
problems begin if they then start another search, they want to keep the
values in the table but the table is cleared and populated with the new
values when they add the results of their new search to it.

STEP: User performs a search.
RESULT: GridView populated with results of search

STEP: User selects items they want to use from the GridView and then click
on the Add To List button.
RESULT: Table control has x amount of rows added containing the details as
they appear in the GridView.

STEP: User then selects more items from the same search.
RESULT: The items selected are appended to the table.

STEP: User performs another search and selects the items from those search
results.
RESULT: Table only shows the items that the user has just selected, all
the
previous items are lost
I've taken a screenshot of the test form to help you visualize it.
(http://mparter.pwp.blueyonder.co.uk/dyntable.png)

Please save me before I go mad

Thanks.

------------------------------------------CODE------------------------------------------------

Protected Sub AddToList()
Dim gridRow As GridViewRow

For Each gridRow In GridView1.Rows

Dim gridCell0 As TableCell = gridRow.Cells(0)
Dim gridCell1 As TableCell = gridRow.Cells(1)
Dim gridCell2 As TableCell = gridRow.Cells(2)
Dim gridCell3 As TableCell = gridRow.Cells(3)
Dim gridCell4 As TableCell = gridRow.Cells(4)

Dim chkStudent As HtmlInputCheckBox =
CType(gridCell0.Controls(1), HtmlInputCheckBox)
If Not (chkStudent Is Nothing) And chkStudent.Checked Then
Dim tblRow As New TableRow
Dim tblCell0 As New TableCell
Dim tblCell1 As New TableCell
Dim tblCell2 As New TableCell
Dim tblCell3 As New TableCell
Dim tblCell4 As New TableCell

Dim chkSelectedStudent As New HtmlInputCheckBox

tblCell0.Controls.Add(chkSelectedStudent)
chkSelectedStudent.ID = "chkSelectedStudent_" &
gridCell1.Text
chkSelectedStudent.Value = gridCell1.Text
tblRow.Cells.Add(tblCell0)
tblCell1.Controls.Add(New LiteralControl(gridCell1.Text))
tblRow.Cells.Add(tblCell1)
tblCell2.Controls.Add(New LiteralControl(gridCell2.Text))
tblRow.Cells.Add(tblCell2)
tblCell3.Controls.Add(New LiteralControl(gridCell3.Text))
tblRow.Cells.Add(tblCell3)
tblCell4.Controls.Add(New LiteralControl(gridCell4.Text))
tblRow.Cells.Add(tblCell4)

Table1.Rows.Add(tblRow)
End If
Next
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Label1.Text = DateTime.Now.ToString
If Page.IsPostBack Then
AddToList()
End If
End Sub

Nov 19 '05 #2
The changes you are making on the client on not known by the server. Since
<tr> and <td> tags are not postable, their new values never make it back to
the server for processing.

One workaround is to use a <input type="hidden"> element on the page as this
is postable. When you are client side adding rows to your table, you should
alter the value of your hidden field. On postback, you parse the hidden
field and on the server, create the rows and columns you need. You will
need two delimiters, one for each column, and one for a new row:

"col1.1^col1.2^col1.3~col1.2^col2.2^col2.3"

<asp:Table id="tblAddons" runat="server" />

Page_Load
{
string tableValue = String.Empty;
if ( Page.IsPostBack )
{
tableValue = Request.Forms["tblAddons_Value"];
RebuildHtmlTable( tableValue );
}

//always register this hidden field with the previous value.
Page.RegisterHiddenField( "tblAddons_Text", tableValue );
}

//in this method you will create the TableRow and TableCell items based on
the string passed to it.
RebuildHtmlTable( string instructions )

HTH,

bill
"Mark Parter" <Ma********@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
I've been at this all day and it's really starting to annoy me now. I have a form, this has a textbox which the user enters a search parameter into. This is passed to a Stored Procedure as a parameter, the results returned are then bound to a GridView control. This GridView control has an extra column with a checkbox in it for every row. The idea for this being that the user selects which items he/she would like to use by checking the checkboxes.

Once they have made their selection, they then click a button and this
copies their selections over to an ASP:Table control. The table control is
declaratively created with each table row being dynamically created.

All of the above works fine using the code included in this post. The
problems begin if they then start another search, they want to keep the
values in the table but the table is cleared and populated with the new
values when they add the results of their new search to it.

STEP: User performs a search.
RESULT: GridView populated with results of search

STEP: User selects items they want to use from the GridView and then click
on the Add To List button.
RESULT: Table control has x amount of rows added containing the details as
they appear in the GridView.

STEP: User then selects more items from the same search.
RESULT: The items selected are appended to the table.

STEP: User performs another search and selects the items from those search
results.
RESULT: Table only shows the items that the user has just selected, all the previous items are lost
I've taken a screenshot of the test form to help you visualize it.
(http://mparter.pwp.blueyonder.co.uk/dyntable.png)

Please save me before I go mad

Thanks.

------------------------------------------CODE---------------------------- --------------------
Protected Sub AddToList()
Dim gridRow As GridViewRow

For Each gridRow In GridView1.Rows

Dim gridCell0 As TableCell = gridRow.Cells(0)
Dim gridCell1 As TableCell = gridRow.Cells(1)
Dim gridCell2 As TableCell = gridRow.Cells(2)
Dim gridCell3 As TableCell = gridRow.Cells(3)
Dim gridCell4 As TableCell = gridRow.Cells(4)

Dim chkStudent As HtmlInputCheckBox =
CType(gridCell0.Controls(1), HtmlInputCheckBox)
If Not (chkStudent Is Nothing) And chkStudent.Checked Then
Dim tblRow As New TableRow
Dim tblCell0 As New TableCell
Dim tblCell1 As New TableCell
Dim tblCell2 As New TableCell
Dim tblCell3 As New TableCell
Dim tblCell4 As New TableCell

Dim chkSelectedStudent As New HtmlInputCheckBox

tblCell0.Controls.Add(chkSelectedStudent)
chkSelectedStudent.ID = "chkSelectedStudent_" & gridCell1.Text chkSelectedStudent.Value = gridCell1.Text
tblRow.Cells.Add(tblCell0)
tblCell1.Controls.Add(New LiteralControl(gridCell1.Text))
tblRow.Cells.Add(tblCell1)
tblCell2.Controls.Add(New LiteralControl(gridCell2.Text))
tblRow.Cells.Add(tblCell2)
tblCell3.Controls.Add(New LiteralControl(gridCell3.Text))
tblRow.Cells.Add(tblCell3)
tblCell4.Controls.Add(New LiteralControl(gridCell4.Text))
tblRow.Cells.Add(tblCell4)

Table1.Rows.Add(tblRow)
End If
Next
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Label1.Text = DateTime.Now.ToString
If Page.IsPostBack Then
AddToList()
End If
End Sub

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: panik | last post by:
Hi, In a custom UserControl class I'm defining a Table (Structure) and two TableRows(Header,Navigation) I'm adding both rows to the Table like this: Structure.Rows.Add(Header);...
5
by: Matthew Louden | last post by:
I created simple ASP.NET web application to test how AutoPostBack property in a web control works. I set AutoPostBack property to be true of a web control. When I run the application, here's the...
2
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control...
8
by: walesboy | last post by:
greetings - I have a btnSubmit button with a Handles btnSubmit.click which works great if all the user does is click that button. But, if the user ALSO changes a text box on the page (which...
4
by: Jim Hammond | last post by:
It would be udeful to be able to get the current on-screen values from a FormView that is databound to an ObjectDataSource by using a callback instead of a postback. For example: public void...
1
by: Timbo | last post by:
Hi all, This is my first message here so i'll try and include all the information that will help you help me out, if possible. Basically I am using C# in ASP.NET 2.0 and have a Repeater...
11
by: antonyliu2002 | last post by:
I know that this has been asked and answered thousands of times. As a matter of fact, I know that I need to say If Not Page.IsPostBack Then 'Do something End If for things that needs to be...
7
by: Tony Girgenti | last post by:
Hello. I'm trying to undetrstand ASP.NET 2.0 and javascript. When i have a button and i click on it and i see the web broswer progress bar at the bottom do something, does that mean that there...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.