• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 708
  • Last Modified:

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

0
TonyReba
Asked:
TonyReba
  • 35
  • 25
1 Solution
 
aledevCommented:
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

0
 
Om PrakashCommented:
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
0
 
TonyRebaAuthor Commented:
can you show how the same code looks in VB?
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
TonyRebaAuthor Commented:
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

0
 
aledevCommented:
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

0
 
TonyRebaAuthor Commented:
I get this error:
'recordsId' is not declared. It may be inaccessible due to its protection level.
0
 
aledevCommented:
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

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

Dim recordsId As New List(Of String)
0
 
TonyRebaAuthor Commented:
do you know why I got the error above , recordsID is not declared?
0
 
aledevCommented:
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)
0
 
TonyRebaAuthor Commented:
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

0
 
aledevCommented:
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

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

or

For Each id As String In recordsId
??
0
 
aledevCommented:
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

0
 
TonyRebaAuthor Commented:
It pulled all my records,

 
0
 
aledevCommented:
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
0
 
TonyRebaAuthor Commented:
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

0
 
TonyRebaAuthor Commented:
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

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

 Dim chb As CheckBox = DirectCast(lvi.FindControl("CheckBoxPrintProvider"), CheckBox)
0
 
aledevCommented:
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
0
 
TonyRebaAuthor Commented:
debugging now, where do those value show sorry,,
0
 
TonyRebaAuthor Commented:
recordsId shows count=0
0
 
aledevCommented:
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
0
 
aledevCommented:
both,first and second page, are Count = 0?
0
 
TonyRebaAuthor Commented:
           Records      Name 'Records' is not declared.      
0
 
TonyRebaAuthor Commented:
I did watch and also the var says

            Records      Name 'Records' is not declared.      
0
 
aledevCommented:
ehm i think you have clicked in the wrong place :)
right click on recordsId after executing the step on those instructions
0
 
TonyRebaAuthor Commented:
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
0
 
aledevCommented:
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

0
 
TonyRebaAuthor Commented:
I see and 189!!!
yuppers now what is next
0
 
TonyRebaAuthor Commented:
records id count 1

exception found in

if chb.Checked Then

Object reference not set to an instance of an object
0
 
aledevCommented:
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

0
 
TonyRebaAuthor Commented:
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
0
 
TonyRebaAuthor Commented:
gnight
0
 
aledevCommented:
hi can you post also the html code of the first page?
0
 
TonyRebaAuthor Commented:
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

0
 
aledevCommented:
what happens if you rename "CheckBoxPrintProvider2" to "CheckBoxPrintProvider"?
0
 
TonyRebaAuthor Commented:
Well the thing is I got two listviews controls thats what I renamed them differently, should I change the name?
0
 
aledevCommented:
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

0
 
TonyRebaAuthor Commented:
Does this goes inside the loop
0
 
aledevCommented:
yes in this loop

For Each lvi As ListViewItem In ListView1.Items
0
 
TonyRebaAuthor Commented:
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

0
 
TonyRebaAuthor Commented:
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 ??
0
 
aledevCommented:
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
0
 
TonyRebaAuthor Commented:
value = Nothing
0
 
aledevCommented:
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

0
 
TonyRebaAuthor Commented:
I cannot see anything  I place the break on the End If Line!!

0
 
aledevCommented:
you get into the if statment?
0
 
TonyRebaAuthor Commented:
I think so,

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

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

http://www.rgvwedding.net/ProviderSearch.aspx.zip
0
 
TonyRebaAuthor Commented:
HI did you get the file?
0
 
aledevCommented:
Downloaded via mobile, i will see it  when go back home
0
 
aledevCommented:
I have found the solution (i really hope xD)

ok you have to remove this procedure "ListView1_ItemDataBound" from the ProviderSearch and add the code posted below
after substitute the query of the "AccessDataSource3" (of the same page) with this (i simply added the ID field in the select)
"SELECT [Id], [First_Name],[Last_Name],[Prof_Designation], [Specialty], [Specialty2],[Address], [Address2], [City], [State], [Zip], [Phone], [Fax], [lat], [lng] FROM [tbl_Providers] ORDER BY [Last_Name]"

and finally add this line inside the ItemTemplate and AlternativeItemTemplate of the ListView2

<asp:Label ID="lblId" runat="server" Visible="false" Text='<%# Eval("Id") %>' />

As you can see this fields are hidden, so there are not visible in the webpage. You need this for save the id associated to the row


Hope for the best :D
Protected Sub ListView2_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ListView2.ItemCommand

        Dim myButtonPrint As Button = CType(ListView2.FindControl("printButton2"), Button)
        If e.CommandSource Is myButtonPrint Then
            Dim recordsId As New List(Of String)
            For Each lvi As ListViewItem In ListView2.Items
                Dim chb As CheckBox = IIf(lvi.FindControl("CheckBoxPrintProvider2") Is Nothing, IIf(lvi.FindControl("CheckBoxPrintProvider3") Is Nothing, lvi.FindControl("CheckBoxPrintProvider4"), lvi.FindControl("CheckBoxPrintProvider3")), lvi.FindControl("CheckBoxPrintProvider2"))

                If chb.Checked = True Then
                    Dim param1 As String
                    param1 = DirectCast(lvi.FindControl("lblId"), Label).Text
                    ' This is the list you will save in Session object
                    'param1 = CType(e.Item.DataItem, System.Data.DataRowView)("ID").ToString()
                    recordsId.Add(param1)

                End If
            Next

            ' Store in session to be pulled out in the Printable Page
            Session("Records") = recordsId
            Response.Redirect("PrintableProviderList.aspx")
        End If
    End Sub

Open in new window

0
 
TonyRebaAuthor Commented:
Yes! Thanks!!!! alot
do you  tested already? do you have both pages handy so you send me?
0
 
TonyRebaAuthor Commented:
what code did you use on page two printable page?
0
 
TonyRebaAuthor Commented:
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
0
 
TonyRebaAuthor Commented:
Many Many thanks !!!!
0
 
aledevCommented:
Yes i tested the page before post the solution
Anyway you are welcome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

  • 35
  • 25
Tackle projects and never again get stuck behind a technical roadblock.
Join Now