Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 7th, 2005, 01:23 PM
Registered User
 
Join Date: Jun 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default asp.net table

Hi,

I am using a WebControls.Table called MYTABLE on my asp.net page. I follow the methods to fill a WebControls.Table as outlined in msdn http://msdn.microsoft.com/library/de...topic.asp.
I also include a checkbox in each row. Everything looks fine here and MyTable does fill up with cells and rows.

When the user checks the box I want to be able to read that the row has been selected. Once the user clicks ok I check MYTABLE.rows.count and it equals 0 now. All previous data is gone and the code to fill MyTable has not been executed.

Enable viewstate is true and I only fill the table if Not Page.IsPostBack.

Thanks for your help in advance.
 
Old April 8th, 2005, 10:37 AM
Authorized User
 
Join Date: Feb 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to deniscuba
Default

you can show me the code related with this page and .aspx for test your code

 
Old April 8th, 2005, 10:52 AM
Registered User
 
Join Date: Jun 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you deniscuba,

             Turns out regardless of what the Page.IsPostBack is you must always
repopulate the webcontrols.table. Somehow asp.net retains the values of the checkboxs after you have refilled the table. My bug now is if you make a second change to the checkboxs asp.net does not retain the client side changes to the checkboxs in the table. This means when a user visits the page you can fill the table with checkboxs and the user can change the state (i.e true or false) of the checkbox. Press submit-->server side repopulates the table with checkboxs I check the state of the checkboxs and they have retained the user changes. But if you do it a second time the changes to the checkbox does not register. Really strange.

Here is the code to populate the table with checkboxs. Below that is the code that loops through the table to check the state of each checkbox

         tempTable is the webcontrols.table on my asp.net form
         oTempDR is a dataread I have already filled

*********************************
'populate our table wtih checkbox
*********************************
        '----------------------------------------------
            'Insert our header table row
            '----------------------------------------------
            Dim tempTRhead As New TableRow
            numcells = oTempDR.FieldCount
            For i = 0 To numcells - 1
                Dim tempTChead As New TableCell
                tempTChead.Controls.Add(New LiteralControl(oTempDR.GetName(i).ToString()))
                tempTRhead.Cells.Add(tempTChead) 'add the cell to the row
                tempTChead = Nothing 'reset our variable
            Next i
            tempTable.Rows.Add(tempTRhead) 'add the row to the table
            '----------------------------------------------
            'Insert our table data rows
            '----------------------------------------------

            While (oTempDR.Read())
                Dim tempTR As New TableRow
                Dim tempTC As New TableCell
                For rowcount = 0 To numcells - 1
                    tempTC = New TableCell
                    tempTC.Text = oTempDR.GetValue(rowcount)
                    tempTR.Cells.Add(tempTC) 'add the cell
                Next rowcount


                'add our control
                Dim tempTCctrl As New TableCell
                Dim tempCheckBox As New CheckBox
                tempId = "chkbox_" & counter.ToString()

                tempCheckBox.Checked = isChecked
                tempTCctrl.Controls.Add(tempCheckBox)
                tempTR.Cells.Add(tempTCctrl) 'add the cell to the row
                tempTC = Nothing

                tempTable.Rows.Add(tempTR) 'add the row
                counter += 1
            End While

************************************************** **********
'loop through our table and check the state of the checkboxs
************************************************** **********

 If tempTable.Rows.Count > 1 Then 'ensure we have data rows to check
'our first row is the header
            For i = 1 To tempTable.Rows.Count - 1
                tempCheckBox = CType(tempTable.Rows(i).Cells(6).Controls.Item(0), CheckBox)
                If tempCheckBox.Checked Then
                     'do something
                End If
            Next
 End If
 
Old April 8th, 2005, 10:55 AM
Registered User
 
Join Date: Jun 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

PS I do clear the table rows before I repopulate them. by using tempTable.rows.clear()
 
Old April 8th, 2005, 03:28 PM
Authorized User
 
Join Date: Feb 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to deniscuba
Default

I think that if de second time that user change the checkbox state in code-behind of this page do'nt executing the same statements that first time, therefore i suggest you that debug the code to verify the stream of execution






Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivot table on web using asp.net raj9211 General .NET 1 May 6th, 2008 11:39 PM
ASP dot net table jijish ASP.NET 2.0 Professional 2 November 22nd, 2007 02:26 AM
ASP.Net Table and Java Script ramuis78 ASP.NET 2.0 Basics 3 February 27th, 2007 02:12 AM
table formatting in asp.net balesh ASP.NET 1.0 and 1.1 Basics 1 June 8th, 2006 07:51 AM
Table control using ASP.Net lily611 General .NET 2 July 30th, 2004 10:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.