Link to home
Start Free TrialLog in
Avatar of TonyReba
TonyRebaFlag for United States of America

asked on

ASP.NET query string parameters

I want to pass the checked checkboxes value of my listview control to a second page so I can display the listview in this second page  with only those selected records

this is what I am have so far , but dont really know how to get it to work the desire way..

Much help is appreciated!!
Protected Sub ListView1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ListView1.ItemDataBound

For Each lvi As ListViewItem In ListView1.Items
            Dim chb As CheckBox = DirectCast(lvi.FindControl("CheckBoxPrintProvider"), CheckBox)

            If chb.Checked Then
                Dim param1 As String
                param1 = CType(e.Item.DataItem, System.Data.DataRowView)("ID").ToString()
                ' Find my Print Button in Listview1 
                Dim myButtonPrint As Button = CType(ListView1.FindControl("PrintButton"), Button)
                ' This code sends only one ID in my querystring I need to pass all checkbixes as parameters
                
                myButtonPrint.PostBackUrl = "PrintableProviderList.aspx?Id=" & param1
                'myButtonPrint.PostBackUrl = "PrintableProviderList.aspx?Id=" & CType(e.Item.DataItem, System.Data.DataRowView)("ID").ToString()

            End If

        Next
        
End Sub

Open in new window

Avatar of aledev
aledev

you put all the records id inside a string array and then save this array into the session state object, so when you will load the second page you have only to read, in the code, the session state object with the records previously saved

i hope this code attached will help you


/***** First page code *****/
Protected Sub ListView1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ListView1.ItemDataBound

For Each lvi As ListViewItem In ListView1.Items
            Dim chb As CheckBox = DirectCast(lvi.FindControl("CheckBoxPrintProvider"), CheckBox)

            // This is the list you will save in Session object
			
			List<string> recordsId=new List<string>();
			
            If chb.Checked Then
                Dim param1 As String
                param1 = CType(e.Item.DataItem, System.Data.DataRowView)("ID").ToString()

				recordsId.Add(param1);
				/* The code below is useless because you don't need to pass parameters anymore */
                ' Find my Print Button in Listview1 
                Dim myButtonPrint As Button = CType(ListView1.FindControl("PrintButton"), Button)
                ' This code sends only one ID in my querystring I need to pass all checkbixes as parameters
                
                myButtonPrint.PostBackUrl = "PrintableProviderList.aspx?Id=" & param1
                'myButtonPrint.PostBackUrl = "PrintableProviderList.aspx?Id=" & CType(e.Item.DataItem, System.Data.DataRowView)("ID").ToString()
				/*----------------------------------------------------*/

				// Now you can save the list
				Session["Records"] = recordsId;
            End If

        Next
        
End Sub


/***** Second page code *****/

protect void Page_Load(object sender, EventArgs e){
	List<string> paramsId = (List<string>)Session["Records"];

	if(null!=paramsId){
		// Put the code for populate the new listview here. Use the list for retrieve the ids
	}
}

Open in new window

declare param1 outside the loop and append all checked values to this string.
Dim param1 As String

For Each lvi As ListViewItem In ListView1.Items

next              

ans set the param after the loop.
myButtonPrint.PostBackUrl = "PrintableProviderList.aspx?Id=" & param1
Avatar of TonyReba

ASKER

can you show how the same code looks in VB?
I am not clear on how retreive the Ids here, can you please help..

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim paramsId As List(Of String) = DirectCast(Session("Records"), List(Of String))
        If (Not (paramsId) Is Nothing) Then
           
                'Put the code for populate the new listview here. Use the list for retrieve the ids

            End If

Listview1 code:


<asp:ListView ID="ListView1" runat="server"   DataSourceID="AccessDataSource2"  >

         <EmptyDataTemplate>
         <span></span>
        </EmptyDataTemplate>
    <GroupTemplate>
            <tr ID="itemPlaceholderContainer" runat="server">
                <td ID="itemPlaceholder" runat="server">
                </td>
            </tr>
        </GroupTemplate>
 
  <ItemTemplate>
        <br />
        <table id="TableItemTemplate"  runat= "server" class="itemTemplateClass">
     
 <tr>
    <td >
      <b>
            <asp:Label ID="Label1" runat="server" Text='<%# Eval("Last_Name") %>' />
            ,
             <asp:Label ID="Label2" runat="server" 
             Text='<%# Eval("First_Name") %>' />
             
               <asp:Label ID="Label3" runat="server" 
             Text='<%# Eval("Prof_Designation") %>' />
             </b>
             </td>
             </tr>
             <tr>
             <td>
            <asp:Label ID="Label4" runat="server" Text='<%# Eval("Specialty") %>' />
            <asp:Label ID="Label5" runat="server" 
            Text='<%# Eval("[Specialty2]") %>' />
            <br/>
            <asp:Label ID="Label6" runat="server" Text='<%# Eval("Address") %>' />
            <br/>
            <asp:Label ID="Label7" runat="server" Text='<%# Eval("Address2") %>' />
           <br/>
            <asp:Label ID="Label8" runat="server" Text='<%# Eval("City") %>' />
            ,
            <asp:Label ID="Label9" runat="server" Text='<%# Eval("State") %>' />
            ,
            <asp:Label ID="Label10" runat="server" Text='<%# Eval("Zip") %>' />
           <br/>
            <asp:Label ID="Label11" runat="server" Text='<%# Eval("Phone") %>' />
            <br/>
            <asp:Label ID="Label12" runat="server" Text='<%# Eval("Fax") %>' />  
            <br />                                         
            </td></tr>
            </table>
            <br />
        </ItemTemplate>

      <AlternatingItemTemplate>
      <table id="TableAlternativeItemTemplate"  runat= "server" class="alternateitemTemplateClass"   >
  <tr>
    <td >
      <b>
            <asp:Label ID="Label13" runat="server" Text='<%# Eval("Last_Name") %>' />
            ,
             <asp:Label ID="Label14" runat="server" 
             Text='<%# Eval("First_Name") %>' />
             
               <asp:Label ID="Label15" runat="server" 
             Text='<%# Eval("Prof_Designation") %>' />
             </b>
             </td>
             </tr>
             <tr>
             <td>
            <asp:Label ID="Label16" runat="server" Text='<%# Eval("Specialty") %>' />
            <asp:Label ID="Label17" runat="server" 
            Text='<%# Eval("[Specialty2]") %>' />
            <br/>
            <asp:Label ID="Label18" runat="server" Text='<%# Eval("Address") %>' />
            <br/>
            <asp:Label ID="Label19" runat="server" Text='<%# Eval("Address2") %>' />
           <br/>
            <asp:Label ID="Label20" runat="server" Text='<%# Eval("City") %>' />
            ,
            <asp:Label ID="Label21" runat="server" Text='<%# Eval("State") %>' />
            ,
            <asp:Label ID="Label22" runat="server" Text='<%# Eval("Zip") %>' />
           <br/>
            <asp:Label ID="Label23" runat="server" Text='<%# Eval("Phone") %>' />
            <br/>
            <asp:Label ID="Label24" runat="server" Text='<%# Eval("Fax") %>' />
            <br />
            </td>
            </tr>
            </table>
       </AlternatingItemTemplate>
   
   <LayoutTemplate>
             
                        <table ID="groupPlaceholderContainer" runat="server" border="1" 
                            style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
                            <tr ID="groupPlaceholder" runat="server">
                            </tr>
                        </table>
                                                
                    </td>
                </tr>
                <tr id="Tr2" runat="server">
                    <td id="Td2" runat="server" 
                        style="text-align: center;background-color: #5D7B9D;font-family: Verdana, Arial, Helvetica, sans-serif;color: #FFFFFF">
                      
                    </td>
                </tr>
            </table>
        </LayoutTemplate>
        
    </asp:ListView>
       
       
       <asp:AccessDataSource ID="AccessDataSource2" runat="server" 
        DataFile="~/App_Data/Providers.accdb" 
        
               SelectCommand="SELECT [First_Name], [Last_Name], [Prof_Designation], [Specialty], [Specialty2], [Address], [Address2], [City], [State], [Zip], [Phone], [Fax] FROM [tbl_Providers] WHERE ([ID] = ?)" >
           <SelectParameters>
               <asp:QueryStringParameter Name="ID" QueryStringField="Id" Type="Int32" />
               
           </SelectParameters>
        </asp:AccessDataSource>
        <br />

</div>

Open in new window

I'm sorry :p i confused the two languages.
This is the code, i also have removed useless lines

i hope there aren't no more errors

Protected Sub ListView1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ListView1.ItemDataBound

		For Each lvi As ListViewItem In ListView1.Items
            
			Dim chb As CheckBox = DirectCast(lvi.FindControl("CheckBoxPrintProvider"), CheckBox)

			' This is the list you will save in Session object
			
			Dim recordsId As New List(Of String)
			
            If chb.Checked Then
                Dim param1 As String
                param1 = CType(e.Item.DataItem, System.Data.DataRowView)("ID").ToString()
				recordsId.Add(param1);
            End If

        Next
		Session("Records") = recordsId;
        
End Sub


'----------- Second page code

Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
	Dim paramsId As List(Of String) = DirectCast(Session("Records"), List(Of String))

	If Not paramsId IsNothing Then
		' Put the code for populate the new listview here. Use the list for retrieve the ids
	End If
End Sub

Open in new window

I get this error:
'recordsId' is not declared. It may be inaccessible due to its protection level.
the last code you have posted makes the difference
anyway, i suggest to create the select command dinamically

try if this works
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim qrySelect As String = "SELECT [First_Name], [Last_Name], [Prof_Designation], [Specialty], [Specialty2], [Address], [Address2], [City], [State], [Zip], [Phone], [Fax] FROM [tbl_Providers] WHERE "
        Dim first As Boolean
        first = True
        For Each id As String In recordsId
            If Not first Then
                qrySelect += "OR "
            End If
            qrySelect += "([ID] = " + id + ") "
        Next
        AccessDataSource2.SelectCommand = qrySelect
    End Sub

Open in new window

yeah  this line must be put before of the "For each" statment

Dim recordsId As New List(Of String)
do you know why I got the error above , recordsID is not declared?
Because the variable is not visible outside the "For Each" block.
my english is no good so i think is better that you see this article

http://en.wikipedia.org/wiki/Scope_(programming)
Thanks for your help so far, I really appreciate it

I get an error in the where clause

Syntax error in WHERE clause
   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim paramsId As List(Of String) = DirectCast(Session("Records"), List(Of String))

        Dim qrySelect As String = "SELECT [First_Name], [Last_Name], [Prof_Designation], [Specialty], [Specialty2], [Address], [Address2], [City], [State], [Zip], [Phone], [Fax] FROM [tbl_Providers] WHERE "
        Dim first As Boolean
        first = True

        For Each id As String In paramsId
            If Not first Then
                qrySelect += "OR "
            End If
            qrySelect += "([ID] = " + id + ") "
        Next
        AccessDataSource2.SelectCommand = qrySelect

Open in new window

ok here you are

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim qrySelect As String = "SELECT [First_Name], [Last_Name], [Prof_Designation], [Specialty], [Specialty2], [Address], [Address2], [City], [State], [Zip], [Phone], [Fax] FROM [tbl_Providers] "
        Dim first As Boolean
        first = True
        For Each id As String In recordsId
            If Not first Then
                qrySelect += "OR "
            Else
                qrySelect += "WHERE "
                first = False
            End If
            qrySelect += "([ID] = " + id + ") "
        Next
        AccessDataSource2.SelectCommand = qrySelect
    End Sub

Open in new window

this is in my second page right?
Is it  
For Each id As String In paramsId

or

For Each id As String In recordsId
??
i'm making a big mess (maybe because it's the time to go to sleep)
use this but is irrelevant:
For Each is As String In recordsId


i posted the code again for be sure


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim qrySelect As String = "SELECT [First_Name], [Last_Name], [Prof_Designation], [Specialty], [Specialty2], [Address], [Address2], [City], [State], [Zip], [Phone], [Fax] FROM [tbl_Providers] "
        Dim first As Boolean
        Dim recordsId As List(Of String) = DirectCast(Session("Records"), List(Of String))

        first = True
        For Each id As String In recordsId
            If Not first Then
                qrySelect += "OR "
            Else
                qrySelect += "WHERE "
                first = False
            End If
            qrySelect += "([ID] = " + id + ") "
        Next
        AccessDataSource2.SelectCommand = qrySelect
    End Sub

Open in new window

It pulled all my records,

 
make sure that this line is executed in the first page:
Session("Records") = recordsId

and make sure that this variable is correctly inizilized in the second one:
Dim recordsId As List(Of String) = DirectCast(Session("Records"), List(Of String))

next, check whether your browser blocks cookies


if everything seems to be ok, post the entire code of the two page so i can take a look
page1 aspx
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Xml
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.Security
Imports System.Xml.Linq
Imports System.IO
Imports System.Convert


Public Class ProviderSearch
    Inherits System.Web.UI.Page


    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
            DataBind()
        End If


        ' DataPager1.PageControlID = ListView1.UniqueID
        ' Programmatically reference to the TextBox Controls to use as Parameters in my Query 
        ' Dim ZipCode As TextBox = CType(Master.FindControl("ContentPlaceHolder1").FindControl("txtZipCode"), TextBox)
        'Dim formParam As New FormParameter("txtZipCode", txtZipCode.Text)
    End Sub


    Protected Sub AccessDataSource2_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles AccessDataSource2.Selecting
        If Not IsPostBack Then
            e.Cancel = True
        End If

    End Sub


    Protected Sub searchButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles searchButton.Click
        ListView1.DataBind()
        ListView1.Visible = True
        ListView2.Visible = False

        If specialityDropDown.SelectedValue = "All" Then

            ' Show All Results 
            ListView2.DataBind()
            ListView1.Visible = False
            ListView2.Visible = True
        End If

        If specialityDropDown.SelectedValue = "All" And (providerTextBox.Text <> "" Or txtZipCode.Text <> "") Then

            ' Show All Results 
            Dim sql As String
            sql = "SELECT [First_Name],[Last_Name],[Prof_Designation], [Specialty], [Specialty2],[Address], [Address2], [City], [State], [Zip], [Phone], [Fax] FROM [tbl_Providers] WHERE (First_Name LIKE '%" + providerTextBox.Text.ToString + " %' OR Last_Name LIKE '%" + providerTextBox.Text.ToString + "%') AND Zip LIKE '%" + txtZipCode.Text.ToString + "%'  "
            'sql = "SELECT [First_Name],[Last_Name],[Prof_Designation], [Specialty], [Specialty2],[Address], [Address2], [City], [State], [Zip], [Phone], [Fax] FROM [tbl_Providers] WHERE (   ((First_Name LIKE '%' +  providerTextBox.Text.ToString + '%') OR (Last_Name LIKE '%' +  providerTextBox.Text.ToString + '%')) OR ( ((First_Name LIKE '%' +  providerTextBox.Text.ToString + '%') OR (Last_Name LIKE '%' +  providerTextBox.Text.ToString + '%')) AND (Zip LIKE '%" + txtZipCode.Text.ToString + "%'   ))) "
            'sql = "SELECT [First_Name],[Last_Name],[Prof_Designation], [Specialty], [Specialty2],[Address], [Address2], [City], [State], [Zip], [Phone], [Fax] FROM [tbl_Providers] WHERE Zip LIKE '%" + txtZipCode.Text.ToString + "%'  "

            'sql = "SELECT [First_Name],[Last_Name],[Prof_Designation], [Specialty], [Specialty2],[Address], [Address2], [City], [State], [Zip], [Phone], [Fax] FROM [tbl_Providers] WHERE ( (Zip LIKE '%" + txtZipCode.Text.ToString + "%') OR  (  (First_Name LIKE '%" + providerTextBox.Text.ToString + "%') OR (Last_Name LIKE '%" + providerTextBox.Text.ToString + "%') )"
            AccessDataSource3.SelectCommand = sql
            ListView1.Visible = False
            ListView2.Visible = True
            ListView2.DataBind()
        End If

    End Sub

    Protected Sub showallButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles showallButton.Click
        ' Show All Results 
        ListView2.DataBind()
        ListView1.Visible = "False"
        ListView2.Visible = "True"
    End Sub




    '#####################  Checkboxes ###################################

    Private ReadOnly Property IDs() As List(Of Integer)
        ' Create a list of ID's that are selected.  ID's is the primary
        ' Key for this table
        Get
            If Me.ViewState("ID") Is Nothing Then
                Me.ViewState("ID") = New List(Of Integer)()
            End If
            Return CType(Me.ViewState("ID"), List(Of Integer))
        End Get
    End Property

    'Protected Sub AddRowstoIDList()
    '    ' Loop through all the current items in the Listview
    '    For Each lvi As ListViewDataItem In ListView1.Items
    '        ' Find the checkbox in each row
    '        Dim CheckBoxPrintProvider As CheckBox = CType(lvi.FindControl("CheckBoxPrintProvider"), CheckBox)
    '        ' If the checkbox is ticked then add the corresponding ID to our private list
    '        If (Not (CheckBoxPrintProvider) Is Nothing) Then
    '            ' Get the ID from the datakeynames property
    '            Dim ID As Integer = Convert.ToInt32(ListView1.DataKeys(lvi.DisplayIndex).Value)
    '            If (CheckBoxPrintProvider.Checked AndAlso Not Me.IDs.Contains(ID)) Then
    '                ' Add the ID to our list
    '                Me.IDs.Add(ID)
    '                '

    '            ElseIf (Not CheckBoxPrintProvider.Checked AndAlso Me.IDs.Contains(ID)) Then
    '                ' Not checked - remove the ID from our list
    '                Me.IDs.Remove(ID)
    '            End If
    '        End If
    '    Next

    'End Sub

    'Protected Sub ListView1_PagePropertiesChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.PagePropertiesChangingEventArgs) Handles ListView1.PagePropertiesChanging
    '    AddRowstoIDList()
    'End Sub

    'Protected Sub ListView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewSortEventArgs) Handles ListView1.Sorting
    '    AddRowstoIDList()
    'End Sub

    Protected Sub ListView1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ListView1.ItemDataBound
        Dim recordsId As New List(Of String)
        For Each lvi As ListViewItem In ListView1.Items
            Dim chb As CheckBox = DirectCast(lvi.FindControl("CheckBoxPrintProvider"), CheckBox)
            ' Check if the checkboxes are checked 
            If chb.Checked Then
                Dim param1 As String
                ' This is the list you will save in Session object

                param1 = CType(e.Item.DataItem, System.Data.DataRowView)("ID").ToString()
                recordsId.Add(param1)
                ' Store in session to be pulled out in the Printable Page
            End If
        Next
        Session("Records") = recordsId
        Dim myButtonPrint As Button = CType(ListView1.FindControl("PrintButton"), Button)
        ' This code sends only one ID in my querystring I need to pass all checkbixes as parameters
        'myButtonPrint.PostBackUrl = "PrintableProviderList.aspx?Id=" & CType(e.Item.DataItem, System.Data.DataRowView)("ID").ToString()
        'Trying to send without parameters 
        myButtonPrint.PostBackUrl = "PrintableProviderList.aspx"
    End Sub

End Class

Open in new window

page two


Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Xml
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.Security
Imports System.Xml.Linq
Imports System.IO
Imports System.Convert


Partial Class PrintableProviderList
    Inherits System.Web.UI.Page



    'Protected Sub PrintButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    '    'If Not Request.QueryString("ID") Is Nothing Then
    '    '    Dim NewsID As String = CType(Request.QueryString("ID"), String)
    '    '    Response.Write(NewsID)
    '    'Else
    '    '    Response.Write("Problem with the first page: No QueryString sent!")
    '    'End If

    '    'ListView1.DataBind()
    '    'Dim sw As New StringWriter()
    '    'Dim hw As New HtmlTextWriter(sw)
    '    'ListView1.RenderControl(hw)
    '    'Dim gridHTML As String = sw.ToString().Replace("""", "'") _
    '    '.Replace(System.Environment.NewLine, "")
    '    'Dim sb As New StringBuilder()
    '    'sb.Append("< type =") 'text/javascript'">")
    '    'sb.Append("window.onload = new function(){")
    '    'sb.Append("var printWin = window.open('', '', 'left=0")
    '    'sb.Append(",top=0,width=1000,height=600,status=0');")
    '    'sb.Append("printWin.document.write(""")
    '    'sb.Append(gridHTML)
    '    'sb.Append(""");")
    '    'sb.Append("printWin.document.close();")
    '    'sb.Append("printWin.focus();")
    '    'sb.Append("printWin.print();")
    '    'sb.Append("printWin.close();};")
    '    'sb.Append("< /script >")
    '    'ClientScript.RegisterStartupScript(Me.GetType(), "GridPrint", sb.ToString())
    '    ''ListView1.PagerSettings.Visible = True
    '    'ListView1.DataBind()


    '    ' Code Working starts here
    '    ' Dim Dl As String = "Datalist Items Checked:<br />"
    '    'For Each dli As ListViewItem In Listview1.Items
    '    'Dim chk As CheckBox = DirectCast(dli.FindControl("ID"), CheckBox)
    '    'If chk.Checked Then
    '    'Dl += (chk.Text + "<br />")
    '    'End If
    '    '   Next
    '    ' DlLiteral.Text = Dl

    'End Sub


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim qrySelect As String = "SELECT [First_Name], [Last_Name], [Prof_Designation], [Specialty], [Specialty2], [Address], [Address2], [City], [State], [Zip], [Phone], [Fax] FROM [tbl_Providers] "
        Dim first As Boolean
        Dim recordsId As List(Of String) = DirectCast(Session("Records"), List(Of String))

        first = True
        For Each ID As String In recordsId
            If Not first Then
                qrySelect += "OR "
            Else
                qrySelect += "WHERE "
                first = False
            End If
            qrySelect += "([ID] = " + ID + ") "
        Next
        AccessDataSource2.SelectCommand = qrySelect


        'Dim paramsId As List(Of String) = DirectCast(Session("Records"), List(Of String))

        'If Not paramsId Is Nothing Then

        '    'Put the code for populate the new listview here. Use the list for retrieve the ids
        '    AccessDataSource2.SelectCommand = "SELECT [First_Name], [Last_Name], [Prof_Designation], [Specialty], [Specialty2], [Address], [Address2], [City], [State], [Zip], [Phone], [Fax] FROM [tbl_Providers] WHERE ([ID] IN &paramsId)"
        '    ' Dim DataView As DataView = DirectCast(DataSource.[Select](DataSourceSelectArguments.Empty), DataView)
        '    ListView1.DataSource = AccessDataSource2
        '    ListView1.DataBind()
        'End If

        ' Dim dvAccess As DataView = DirectCast(AccessDataSource2.Select(DataSourceSelectArguments.Empty), DataView)
        ' For Each drvAccess As DataRowView In dvAccess

        ' Next



        '' Find the server name on the previous page
        'Dim txt As New ListView
        'txt = CType(Page.PreviousPage.FindControl _
        '    ("listview1"), ListView)

        ''    Find the checkbox   check if it is checked or not

        'For Each lvi As ListViewItem In ListView1.Items
        '    Dim chb As CheckBox = DirectCast(Page.PreviousPage.FindControl("CheckBoxPrintProvider"), CheckBox)
        '    If chb.Checked Then
        '        CheckBox1.Text = chb.Text
        '        ListView1 = txt
        '    End If
        '        Next 
        ''If Session("mystringarray") IsNot Nothing Then
        '' valuepage1 = Session("mystringarray").ToString()
        '' End If

        'Dim txt As CheckBox
        'Dim ctContent As Control
        'Dim ct As Control
        'Dim myCheck As CheckBox
        'ctContent = Me.PreviousPage.Controls(0).FindControl("ContentPlaceHolder1")
        'myCheck.Text = ctContent.FindControl("CheckBoxPrintProvider")

        'If Not IsNothing(ct) Then
        '    CheckBox1.Text = Server.HtmlEncode(ct.Text)
        'Else
        'CheckBox1.Text = "[Name Not available]"
        'End If
    End Sub



End Class

Open in new window

sorry for the mess, I have tried many different methods
I think the issue might be the page is not finding

 Dim chb As CheckBox = DirectCast(lvi.FindControl("CheckBoxPrintProvider"), CheckBox)
Everything seems ok and i guess you have checked whether your browser had cookies enabled..

put a breakpoint here in the first page
140: Session("Records") = recordsId
 
and here in the second page:
70: Dim recordsId As List(Of String) = DirectCast(Session("Records"), List(Of String))


tell me the value of the both recordsId after the line is executed
debugging now, where do those value show sorry,,
recordsId shows count=0
While in break mode, right-click a variable name in the source window name and choose QuickWatch. This automatically places the variable into the QuickWatch dialog box, so you can see the value
both,first and second page, are Count = 0?
           Records      Name 'Records' is not declared.      
I did watch and also the var says

            Records      Name 'Records' is not declared.      
ehm i think you have clicked in the wrong place :)
right click on recordsId after executing the step on those instructions
this is waht i am doing,

I set a break point on both lines as you told me . then I click start debugging

then page open and sent me to code, then I right clicked the variable where it says addd watch , then the value that show is count =0 , i clicked continue and thats what it shows. I dont get to page2
look whether you step into this block
if no could mean that there is a problem retrieving the checkbox as you mentioned before

If chb.Checked Then
                Dim param1 As String
                ' This is the list you will save in Session object

                param1 = CType(e.Item.DataItem, System.Data.DataRowView)("ID").ToString()
                recordsId.Add(param1)
                ' Store in session to be pulled out in the Printable Page
            End If

Open in new window

I see and 189!!!
yuppers now what is next
records id count 1

exception found in

if chb.Checked Then

Object reference not set to an instance of an object
try to add this on the page, before this line:

<asp:Label ID="Label1" runat="server" Text='<%# Eval("Last_Name") %>' />


<asp:CheckBox id="CheckBoxPrintProvider"
                    AutoPostBack="false"
                    runat="server"/>

Open in new window

I removed checkbox test to see what happens

and i get

+            recordsId      Count = 1      System.Collections.Generic.List(Of String)
            param1      "363"      String

param1 keeps incrementing but I use recordsId in second page
gnight
hi can you post also the html code of the first page?
here it is thanks!
<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="ProviderSearch.aspx.vb" Inherits="ProviderSearch" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script src="Scripts/Script.js" type="text/javascript"></script>
     <script type="text/javascript">

         // Let's use a lowercase function name to keep with JavaScript conventions

         function selectAll(invoker) {

             // Since ASP.NET checkboxes are really HTML input elements
             //  let's get all the inputs 
             var inputElements = document.getElementsByTagName('input');
             for (var i = 0; i < inputElements.length; i++) {

                 var myElement = inputElements[i];
                 // Filter through the input types looking for checkboxes
                 if (myElement.type === "checkbox") {

                     // Use the invoker (our calling element) as the reference 
                     //  for our checkbox status
                     myElement.checked = invoker.checked;
                 }

             }

         }  

     </script>

     

   <br />
    <div class="NoDisplay" id="SearchTable" 
    style="BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: none; margin-right: 14px;">
    <table cellpadding="0" cellspacing="0" style="border-right: #000000 thin solid; border-top: #000000 thin solid;
                                    border-left: #000000 thin solid; border-bottom: #000000 thin solid; background-color: #FFFFFF; border-width: 1px;"
                                    width="98%" align="center">
    <tr>
        <td colspan="2" style="width: 100%; height: 22px; text-align: left;">
            <span style="font-size: 10pt; font-family:Arial, Helvetica, sans-serif;">
            <strong style="width: 100%; text-align: center">&nbsp;Search Options</strong></span></td>
    </tr>
    <tr style="font-size: 12pt">
        <td style="width: 34%; text-align: left; height: 24px;">
                                            <span id="providerLabel" style="font-family:Arial, Helvetica, sans-serif;font-size:10pt;">&nbsp;Provider Name:</span>
            <asp:TextBox ID="providerTextBox" runat="server"></asp:TextBox>
            <span style="font-size: 10pt">&nbsp;&nbsp; (All or part of name)</span></td>
        <td style="width: 30%; height: 24px; text-align: left;">
            
        </td>
    </tr>
    <tr>
        <td style="width: 34%; text-align: left; height: 20px;">
            <span id="specialtyLabel" 
            style="font-family:Arial, Helvetica, sans-serif;font-size:10pt; text-align: left;">&nbsp;Specialty:</span>
            <asp:DropDownList ID="specialityDropDown" runat="server" 
                DataSourceID="AccessDataSource1" DataTextField="Specialty" 
                DataValueField="Specialty"  AppendDataBoundItems="true">
           <asp:ListItem Selected="True"  Text="All" Value ="All">All</asp:ListItem>                   
            </asp:DropDownList>
        </td>
        <td style="width: 30%; height: 20px; text-align: left;">
            <asp:Button ID="searchButton" runat="server" Text="Search" />
        </td>
    </tr>
    <tr>
        <td style="width: 34%; text-align: left; height: 21px;">
            <span id="zipCodeLabel" style="font-family:Arial, Helvetica, sans-serif;font-size:10pt;">&nbsp;Zip Code:</span>
            <asp:TextBox ID="txtZipCode" runat="server"></asp:TextBox>
&nbsp;
            <asp:DropDownList ID="distanceDropDown"  runat="server">
                <asp:ListItem Selected="True" Value ="1000">Find Closest</asp:ListItem>
                <asp:ListItem Value ="10">Within 10 Miles</asp:ListItem>
                <asp:ListItem Value ="25">Within 25 Miles</asp:ListItem>
                <asp:ListItem Value ="50">Within 50 Miles</asp:ListItem>
                <asp:ListItem Value ="100">Within 100 Miles</asp:ListItem>
            </asp:DropDownList>
            
        </td>
        <td style="width: 30%; height: 21px; text-align: left;">
            <asp:Button ID="showallButton" runat="server" Text="Show All" />
            <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
                DataFile="~/App_Data/Providers.mdb" 
                
                SelectCommand="SELECT DISTINCT [Specialty] FROM [tbl_Providers] ORDER BY [Specialty] ASC">
            </asp:AccessDataSource>
        </td>
    </tr>
    <tr>
        <td style="width: 34%; text-align: left; height: 21px;">&nbsp;
            </td>
        <td style="width: 30%; height: 21px; text-align: left;">&nbsp;
            </td>
    </tr>
</table>
    <br />
    </div> 
    <!--   ENDS NO-DISPLAY PRINT AREA--> 


    <div id="print_area">

    <asp:ListView ID="ListView1" runat="server"   DataSourceID="AccessDataSource2" 
        Visible="False"  >

         <EmptyDataTemplate>
         <span></span>
        </EmptyDataTemplate>
    <GroupTemplate>
            <tr ID="itemPlaceholderContainer" runat="server">
                <td ID="itemPlaceholder" runat="server">
                </td>
            </tr>
        </GroupTemplate>
 
  <ItemTemplate>
        <br />
        <table id="TableItemTemplate"  runat= "server" class="itemTemplateClass">
     
 <tr>
    <td >
      <b>
            <asp:Label ID="Label1" runat="server" Text='<%# Eval("Last_Name") %>' />
            ,
             <asp:Label ID="Label2" runat="server" 
             Text='<%# Eval("First_Name") %>' />
             
               <asp:Label ID="Label3" runat="server" 
             Text='<%# Eval("Prof_Designation") %>' />
             </b>
             </td>
             </tr>
             <tr>
             <td>
            <asp:Label ID="Label4" runat="server" Text='<%# Eval("Specialty") %>' />
            <asp:Label ID="Label5" runat="server" 
            Text='<%# Eval("[Specialty2]") %>' />
            <br/>
            <asp:Label ID="Label6" runat="server" Text='<%# Eval("Address") %>' />
            <br/>
            <asp:Label ID="Label7" runat="server" Text='<%# Eval("Address2") %>' />
           <br/>
            <asp:Label ID="Label8" runat="server" Text='<%# Eval("City") %>' />
            ,
            <asp:Label ID="Label9" runat="server" Text='<%# Eval("State") %>' />
            ,
            <asp:Label ID="Label10" runat="server" Text='<%# Eval("Zip") %>' />
           <br/>
            <asp:Label ID="Label11" runat="server" Text='<%# Eval("Phone") %>' />
            <br/>
            <asp:Label ID="Label12" runat="server" Text='<%# Eval("Fax") %>' />  
            <br />
            <asp:CheckBox ID="CheckBoxPrintProvider" runat="server" Text='<%#Eval("ID")%>'/>
             <asp:HiddenField ID="hdnID" runat="server" Value='<%#Eval("ID")%>' />
             <asp:HyperLink ID="HyperLink1"  runat="server" Text="Click to See a Map" NavigateUrl='<%# "http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=" + Server.UrlEncode(Eval("Address").ToString) + "," + Server.UrlEncode(Eval("City").ToString) + "," + Server.UrlEncode(Eval("State").ToString) %>'   />                                             
               
                    
            
            </td></tr>
            </table>
            <br />
        </ItemTemplate>

      <AlternatingItemTemplate>
      <table id="TableAlternativeItemTemplate"  runat= "server" class="alternateitemTemplateClass"   >
  <tr>
    <td >
      <b>
            <asp:Label ID="Label1" runat="server" Text='<%# Eval("Last_Name") %>' />
            ,
             <asp:Label ID="Label2" runat="server" 
             Text='<%# Eval("First_Name") %>' />
             
               <asp:Label ID="Label3" runat="server" 
             Text='<%# Eval("Prof_Designation") %>' />
             </b>
             </td>
             </tr>
             <tr>
             <td>
            <asp:Label ID="Label4" runat="server" Text='<%# Eval("Specialty") %>' />
            <asp:Label ID="Label5" runat="server" 
            Text='<%# Eval("[Specialty2]") %>' />
            <br/>
            <asp:Label ID="Label6" runat="server" Text='<%# Eval("Address") %>' />
            <br/>
            <asp:Label ID="Label7" runat="server" Text='<%# Eval("Address2") %>' />
           <br/>
            <asp:Label ID="Label8" runat="server" Text='<%# Eval("City") %>' />
            ,
            <asp:Label ID="Label9" runat="server" Text='<%# Eval("State") %>' />
            ,
            <asp:Label ID="Label10" runat="server" Text='<%# Eval("Zip") %>' />
           <br/>
            <asp:Label ID="Label11" runat="server" Text='<%# Eval("Phone") %>' />
            <br/>
            <asp:Label ID="Label12" runat="server" Text='<%# Eval("Fax") %>' />
            
            <br />
            <asp:CheckBox ID="CheckBoxPrintProvider2" runat="server" Text="Print this Provider" />
            <asp:HyperLink ID="HyperLink2"  runat="server" Text="Click to See a Map" NavigateUrl='<%# "http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=" + Server.UrlEncode(Eval("Address").ToString) + "," + Server.UrlEncode(Eval("City").ToString) + "," + Server.UrlEncode(Eval("State").ToString) %>'   />
            </td>
            </tr>
            </table>
       </AlternatingItemTemplate>
   
   <LayoutTemplate>

   
             <table id="Table1" cellpadding="0" cellspacing="0" style="border-right: #000000 thin solid; border-top: #000000 thin solid;
                                    border-left: #000000 thin solid; border-bottom: #000000 thin solid; background-color: #FFFFFF; border-width: 1px; margin-right: 13%;"
                                    width="98%" align="center" >
        <tr>
            <td class="style2">
                    <b>Matching Providers </b>
                   </td>
                   <br />
            <td>&nbsp;
                </td>
        </tr>
        <tr>
            <td class="style2">
                             Sort By: 
                                 <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Sort" CommandArgument="Last_Name">Name</asp:LinkButton>&nbsp;Sort 
                By:   
                                 <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Sort" CommandArgument="City">City</asp:LinkButton>
                <br />
            </td>
            <td>
     <asp:Button Id="printButton"   runat="server" Text="Print Selected Providers" />
     <asp:CheckBox ID="chkSelectAll" runat="server" Text=" Select All For Printing" AutoPostBack="true" OnClick="selectAll(this)" />
                                 
                                    
                                    </td>
        </tr>
    </table>
    
                        <table ID="groupPlaceholderContainer" runat="server" border="1" 
                            style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
                            <tr ID="groupPlaceholder" runat="server">
                            </tr>
                        </table>
                                                
                    </td>
                </tr>
                <tr id="Tr2" runat="server">
                    <td id="Td2" runat="server" 
                        style="text-align: center;background-color: #5D7B9D;font-family: Verdana, Arial, Helvetica, sans-serif;color: #FFFFFF">
                        <br />
                        <asp:DataPager ID="DataPager1" runat="server" PageSize="12">
                            <Fields>
                                <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                                    ShowLastPageButton="True" />
                            </Fields>
                        </asp:DataPager>
                    </td>
                </tr>
            </table>
             
        </LayoutTemplate>
        
    </asp:ListView>
       
 
       <asp:AccessDataSource ID="AccessDataSource2" runat="server" 
        DataFile="~/App_Data/Providers.mdb" 
        SelectCommand="SELECT [Id],[First_Name],[Last_Name],[Prof_Designation], [Specialty], [Specialty2],[Address], [Address2], [City], [State], [Zip], [Phone], [Fax] FROM [tbl_Providers] WHERE  
        ((@First_Name IS NULL OR First_Name LIKE '%' +  @First_Name + '%') OR
        (@Last_Name IS NULL OR Last_Name LIKE '%' +  @Last_Name + '%')) AND
        (@Specialty IS NULL OR Specialty LIKE '%' + @Specialty + '%') AND  
        (@Zip IS NULL OR Zip LIKE '%' + @Zip + '%')"
         CancelSelectOnNullParameter="False">
        <SelectParameters>

        <asp:ControlParameter ControlID="providerTextBox" Name="First_Name"  PropertyName ="Text" Type="String"  ConvertEmptyStringToNull ="true" />
        <asp:ControlParameter ControlID="providerTextBox" Name="Last_Name"  PropertyName ="Text" Type="String"  ConvertEmptyStringToNull ="true" />
        <asp:ControlParameter ControlID="specialityDropDown" Name="Specialty" PropertyName ="SelectedValue" Type="String" ConvertEmptyStringToNull ="true" />
        <asp:ControlParameter ControlID="txtZipCode" Name="Zip" PropertyName ="Text" Type="String" ConvertEmptyStringToNull ="true"  />

        
     </SelectParameters>
       
        </asp:AccessDataSource>
                
           <br />
    <asp:AccessDataSource ID="AccessDataSource3" runat="server" 
           DataFile="~/App_Data/Providers.mdb" 
        SelectCommand="SELECT [First_Name],[Last_Name],[Prof_Designation], [Specialty], [Specialty2],[Address], [Address2], [City], [State], [Zip], [Phone], [Fax], [lat], [lng] FROM [tbl_Providers] ORDER BY [Last_Name]"
         CancelSelectOnNullParameter="False">
        <SelectParameters>

        <asp:ControlParameter ControlID="providerTextBox" Name="First_Name"  PropertyName ="Text" Type="String"  ConvertEmptyStringToNull ="true" />
        <asp:ControlParameter ControlID="specialityDropDown" Name="Specialty" PropertyName ="SelectedValue" Type="String" ConvertEmptyStringToNull ="true" />
        <asp:ControlParameter ControlID="txtZipCode" Name="Zip" PropertyName ="Text" Type="String" ConvertEmptyStringToNull ="true"  />
        
     </SelectParameters>
    </asp:AccessDataSource>
                
    <asp:ListView ID="ListView2" runat="server"   
        DataSourceID="AccessDataSource3" GroupPlaceholderID="groupPlaceholder2" 
        ItemPlaceholderID="itemPlaceholder2" Visible="False"  >

         <EmptyDataTemplate>
         <span></span>
        </EmptyDataTemplate>
    <GroupTemplate>
            <tr ID="itemPlaceholderContainer2" runat="server">
                <td ID="itemPlaceholder2" runat="server">
                </td>
            </tr>
        </GroupTemplate>
 
  <ItemTemplate>
        <br />
        <table id="TableItemTemplate0"  runat= "server" class="itemTemplateClass">
     
 <tr>
    <td >
      <b>
            <asp:Label ID="Label13" runat="server" Text='<%# Eval("Last_Name") %>' />
            ,
             <asp:Label ID="Label14" runat="server" 
             Text='<%# Eval("First_Name") %>' />
             
               <asp:Label ID="Label15" runat="server" 
             Text='<%# Eval("Prof_Designation") %>' />
             </b>
             </td>
             </tr>
             <tr>
             <td>
            <asp:Label ID="Label16" runat="server" Text='<%# Eval("Specialty") %>' />
            <asp:Label ID="Label17" runat="server" 
            Text='<%# Eval("[Specialty2]") %>' />
            <br/>
            <asp:Label ID="Label18" runat="server" Text='<%# Eval("Address") %>' />
            <br/>
            <asp:Label ID="Label19" runat="server" Text='<%# Eval("Address2") %>' />
           <br/>
            <asp:Label ID="Label20" runat="server" Text='<%# Eval("City") %>' />
            ,
            <asp:Label ID="Label21" runat="server" Text='<%# Eval("State") %>' />
            ,
            <asp:Label ID="Label22" runat="server" Text='<%# Eval("Zip") %>' />
           <br/>
            <asp:Label ID="Label23" runat="server" Text='<%# Eval("Phone") %>' />
            <br/>
            <asp:Label ID="Label24" runat="server" Text='<%# Eval("Fax") %>' />  
            <br />
            <asp:CheckBox ID="CheckBoxPrintProvider3" runat="server" Text="Print this Provider" />
            <asp:HyperLink ID="HyperLink3"  runat="server" Text="Click to See a Map" NavigateUrl='<%# "http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=" + Server.UrlEncode(Eval("Address").ToString) + "," + Server.UrlEncode(Eval("City").ToString) + "," + Server.UrlEncode(Eval("State").ToString) %>'   />
                                                   
            </td></tr>
            </table>
            <br />
        </ItemTemplate>

      <AlternatingItemTemplate>
      <br />
      <table id="TableAlternativeItemTemplate0"  runat= "server" 
              class="alternateitemTemplateClass"   >
        <tr>
        <td >
        <b>
            <asp:Label ID="Label25" runat="server" Text='<%# Eval("Last_Name") %>' />
            ,
             <asp:Label ID="Label26" runat="server" 
             Text='<%# Eval("First_Name") %>' />
             
               <asp:Label ID="Label27" runat="server" 
             Text='<%# Eval("Prof_Designation") %>' />
             </b>
             </td>
             </tr>
             <tr>
             <td>
            <asp:Label ID="Label28" runat="server" Text='<%# Eval("Specialty") %>' />
            <asp:Label ID="Label29" runat="server" 
            Text='<%# Eval("[Specialty2]") %>' />
            <br/>
            <asp:Label ID="Label30" runat="server" Text='<%# Eval("Address") %>' />
            <br/>
            <asp:Label ID="Label31" runat="server" Text='<%# Eval("Address2") %>' />
           <br/>
            <asp:Label ID="Label32" runat="server" Text='<%# Eval("City") %>' />
            ,
            <asp:Label ID="Label33" runat="server" Text='<%# Eval("State") %>' />
            ,
            <asp:Label ID="Label34" runat="server" Text='<%# Eval("Zip") %>' />
           <br/>
            <asp:Label ID="Label35" runat="server" Text='<%# Eval("Phone") %>' />
            <br/>
            <asp:Label ID="Label36" runat="server" Text='<%# Eval("Fax") %>' />
            
            <br />
            <asp:CheckBox ID="CheckBoxPrintProvider4" runat="server" Text="Print this Provider" />
            <asp:HyperLink ID="HyperLink4"  runat="server" Text="Click to See a Map" NavigateUrl='<%# "http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=" + Server.UrlEncode(Eval("Address").ToString) + "," + Server.UrlEncode(Eval("City").ToString) + "," + Server.UrlEncode(Eval("State").ToString) %>'   />
            </td>
            </tr>
            </table>
            
   </AlternatingItemTemplate>
   
   <LayoutTemplate>
   
       <table id="Table2"cellpadding="0" cellspacing="0" style="border-right: #000000 thin solid; border-top: #000000 thin solid;
                                    border-left: #000000 thin solid; border-bottom: #000000 thin solid; background-color: #FFFFFF; border-width: 1px;"
                                    width="100%" align="center">
        <tr>
            <td >
                    <b>Matching Providers </b>
                   </td>
            <td>&nbsp;
                </td>
        </tr>
        <tr>
            <td>
                             Sort By: 
                                 <asp:LinkButton ID="LinkButton3" runat="server" CommandName="Sort" CommandArgument="Last_Name">Name</asp:LinkButton>
                                 <asp:LinkButton ID="LinkButton4" runat="server" CommandName="Sort" CommandArgument="City">City</asp:LinkButton>  
                                 <asp:LinkButton ID="LinkButton5" runat="server" CommandName="Sort" CommandArgument="Specialty">Specialty</asp:LinkButton>
                                 <br />
            </td>
            <td>
                        <asp:Button ID="PrintButton2" runat="server" Text="Print Selected Providers" />
                   &nbsp;
                   <asp:CheckBox ID="chkSelectAll2" runat="server" Text=" Select All For Printing" AutoPostBack="true" OnClick="selectAll(this)" />
                                    </td>
        </tr>
    </table>




                        <table ID="groupPlaceholderContainer2" runat="server" border="1" 
                            
                            style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
                            <tr ID="groupPlaceholder2" runat="server">
                            </tr>
                        </table>

                        
                    </td>
                </tr>
                <tr id="Tr6" runat="server">
                    <td id="Td4" runat="server" 
                        
                        style="text-align: center;background-color: #5D7B9D;font-family: Verdana, Arial, Helvetica, sans-serif;color: #FFFFFF">
                        <br />
                        <asp:DataPager ID="DataPager2" runat="server" PageSize="12">
                            <Fields>
                                <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                                    ShowLastPageButton="True" />
                            </Fields>
                        </asp:DataPager>
                    </td>
                </tr>
            </table>
        </LayoutTemplate>
            </asp:ListView>
       </div> 
 
           <br />
</asp:Content>

Open in new window

what happens if you rename "CheckBoxPrintProvider2" to "CheckBoxPrintProvider"?
Well the thing is I got two listviews controls thats what I renamed them differently, should I change the name?
mmh not the listview, i think that the problem is the "AlternativeItemTemplate". Both the ItemTemplate and AlternativeItemTemplate have the same structure, but different id for the object. So when you try to get the checkbox in the code through the FindControl funcion will return null because the checkbox inside the  AlternativeItemTemplate tag has a different id.

i think this code should works fine, but try also to give the same id of ItemTemplate checkbox to the other one inside AlternativeItemTemplate
Dim chb As CheckBox = DirectCast(lvi.FindControl("CheckBoxPrintProvider"), CheckBox)
if chb IsNothing Then
    chb = DirectCast(lvi.FindControl("CheckBoxPrintProvider2"), CheckBox)
End If
            ' Check if the checkboxes are checked 
            If chb.Checked Then
                Dim param1 As String
                ' This is the list you will save in Session object

                param1 = CType(e.Item.DataItem, System.Data.DataRowView)("ID").ToString()
                recordsId.Add(param1)
                ' Store in session to be pulled out in the Printable Page
            End If

Open in new window

Does this goes inside the loop
yes in this loop

For Each lvi As ListViewItem In ListView1.Items
It still shows all the records on page2
    Protected Sub ListView1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ListView1.ItemDataBound
        Dim recordsId As New List(Of String)
        ' Dim chb As CheckBox = DirectCast(ListView1.FindControl("CheckBoxPrintProvider"), CheckBox)
        For Each lvi As ListViewItem In ListView1.Items
            Dim chb As CheckBox = DirectCast(lvi.FindControl("CheckBoxPrintProvider"), CheckBox)
            If ((chb) Is Nothing) Then
                chb = DirectCast(lvi.FindControl("CheckBoxPrintProvider2"), CheckBox)
            End If
            ' Check if the checkboxes are checked 
            If chb.Checked Then
                Dim param1 As String
                ' This is the list you will save in Session object

                param1 = CType(e.Item.DataItem, System.Data.DataRowView)("ID").ToString()
                recordsId.Add(param1)
                ' Store in session to be pulled out in the Printable Page
            End If
        Next
        ' Store in session to be pulled out in the Printable Page
        Session("Records") = recordsId
        Dim myButtonPrint As Button = CType(ListView1.FindControl("PrintButton"), Button)
        ' Go to Printable page 
        'myButtonPrint.Attributes.Add("onclick", "return SelectAll(id)")
        myButtonPrint.PostBackUrl = "PrintableProviderList.aspx"
    End Sub

End Class

Open in new window

I am debugging page 2
Dim recordsId As List(Of String) = DirectCast(Session("Records"), List(Of String))

and value shows = Nothing  

can this be the issue ??
at this point i really don't know what think..

what is the value of "chb" after this lines?

Dim chb As CheckBox = DirectCast(lvi.FindControl("CheckBoxPrintProvider"), CheckBox)
if chb IsNothing Then
    chb = DirectCast(lvi.FindControl("CheckBoxPrintProvider2"), CheckBox)
End If
value = Nothing
it's more hard than i thought :)
put the code below after this line
       For Each lvi As ListViewItem In ListView1.Items
tell me the value of chkId or the values if there are more than one
' check all child control of the listviewitem object
            Dim chkId As String
            For Each c As Control In lvi.Controls
                ' if the current control is a checkbox
                If c.GetType() Is GetType(CheckBox) Then
                    ' get the id
                    chkId = DirectCast(c, CheckBox).ID
                    ' put a breakpoint to see the value of chkId
                End If
            Next

Open in new window

I cannot see anything  I place the break on the End If Line!!

you get into the if statment?
I think so,

this is i see
chb    'chb' is not declared.....
recordsId    """"

param1 param1 is not declared
can you post your solution zipped?
let me uploaded hold on
please go to and let me know if you are able to download it

http://www.rgvwedding.net/ProviderSearch.aspx.zip
HI did you get the file?
Downloaded via mobile, i will see it  when go back home
ASKER CERTIFIED SOLUTION
Avatar of aledev
aledev

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes! Thanks!!!! alot
do you  tested already? do you have both pages handy so you send me?
what code did you use on page two printable page?
NeverMind It works great!!  Just need to the same in ListView1 and willl be ok....Thanks for all your help and time you a really great programmer appreciate all your help in solving this
Many Many thanks !!!!
Yes i tested the page before post the solution
Anyway you are welcome