Solved

ASP.NET Maintaining Checkbox State LisView Pagination

Posted on 2012-03-19
3
510 Views
Last Modified: 2012-03-24
I am trying to maintain the state of the checkbox inside the listview item template, can someone help me to point out the code that I would need to?

aspx
<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false"
    CodeFile="ProviderSearch.aspx.vb" Inherits="ProviderSearch" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<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 />
    <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; margin-right: 17px;" width="98%" align="center" id="SearchOptionstbl">
        <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;(All or part of name)</span>
            </td>
            <td style="width: 30%; height: 24px; text-align: left;">
                <asp:Label ID="Label1" runat="server"></asp:Label>
            </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>
            <span style="margin-left: 31px">
                <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> </span>
            </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: 17px;">
                <span id="zipCodeLabel" style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt;">
                    &nbsp;Zip Code:</span>
                <span style="margin-left: 34px"> 
                <asp:TextBox ID="txtZipCode" runat="server"></asp:TextBox>
                &nbsp;</span> 
                <asp:DropDownList ID="distanceDropDown" runat="server" Visible="False">
                    <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: 17px; 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 />

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
            </asp:ToolkitScriptManager>


    <asp:UpdatePanel ID="UpdatePanel1" runat="server">

    <ContentTemplate >

    <asp:ListView ID="ListView1" runat="server" DataSourceID="AccessDataSource2" Visible="False"
        ItemPlaceholderID="itemPLaceHolder1" GroupPlaceholderID="groupPlaceholder1" 
            DataKeyNames="ID">
        <EmptyDataTemplate>
            <span></span>
            
        </EmptyDataTemplate>
        <GroupTemplate>
            <tr id="itemPlaceholderContainer" runat="server">
                <td id="itemPlaceholder1" 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") %>' Visible='<%# IIF(CONVERT.ToString(DataBinder.Eval(Container.DataItem, "Last_Name"))="",False,True)%>'/>
                            <asp:Label ID="LabelComma" runat="server" Text=',' Visible='<%# IIF(CONVERT.ToString(DataBinder.Eval(Container.DataItem, "Last_Name"))="",False,True)%>'/>                                                   
                             
                            <asp:Label ID="Label2" runat="server" Text='<%# Eval("First_Name") %>' Visible='<%# IIF(CONVERT.ToString(DataBinder.Eval(Container.DataItem, "First_Name"))="",False,True)%>'/>
                            <asp:Label ID="Label3" runat="server" Text='<%# Eval("Prof_Designation") %>' Visible='<%# IIF(CONVERT.ToString(DataBinder.Eval(Container.DataItem, "Prof_Designation"))="",False,True)%>'/>
                        </b>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label4" runat="server" Text='<%# Eval("Specialty") %>' Visible='<%# IIF(CONVERT.ToString(DataBinder.Eval(Container.DataItem, "Specialty"))="",False,True)%>'/>
                        <asp:Label ID="Label5" runat="server" Text='<%# Eval("[Specialty2]") %>' Visible='<%# IIF(CONVERT.ToString(DataBinder.Eval(Container.DataItem, "Specialty2"))="",False,True)%>'/>
                        <br />
                        
                        <asp:Label ID="Label6" runat="server" Text='<%# Eval("Address") %>' Visible='<%# IIF(CONVERT.ToString(DataBinder.Eval(Container.DataItem, "Address"))="",False,True)%>'/>
                        <br />
                        <asp:Label ID="Label7" runat="server" Text='<%# Eval("Address2") %>' Visible='<%# IIF(CONVERT.ToString(DataBinder.Eval(Container.DataItem, "Address2"))="",False,True)%>'/>
                        <br />
                        <asp:Label ID="Label8" runat="server" Text='<%# Eval("City") %>' Visible='<%# IIF(CONVERT.ToString(DataBinder.Eval(Container.DataItem, "City"))="",False,True)%>'/>
                        ,
                        <asp:Label ID="Label9" runat="server" Text='<%# Eval("State") %>' Visible='<%# IIF(CONVERT.ToString(DataBinder.Eval(Container.DataItem, "State"))="",False,True)%>'/>
                        ,
                        <asp:Label ID="Label10" runat="server" Text='<%# Eval("Zip") %>' Visible='<%# IIF(CONVERT.ToString(DataBinder.Eval(Container.DataItem, "Zip"))="",False,True)%>'/>
                        <br />
                        <asp:Label ID="Label11" runat="server" Text='<%# Eval("Phone") %>' Visible='<%# IIF(CONVERT.ToString(DataBinder.Eval(Container.DataItem, "Phone"))="",False,True)%>'/>
                        <br />
                        <asp:Label ID="Label12" runat="server" Text='<%# Eval("Fax") %>' Visible='<%# IIF(CONVERT.ToString(DataBinder.Eval(Container.DataItem, "Fax"))="",False,True)%>'/>
                        <br />
                        <asp:Label ID="lblId1" runat="server" Visible="false" Text='<%# Eval("Id") %>' />
                        <asp:CheckBox ID="CheckBoxPrintProvider1" runat="server" EnableViewState="true" AutoPostBack="True" />


                        <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) %>' Target="_blank" />
                    </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") %>'  Visible='<%# IIF(CONVERT.ToString(DataBinder.Eval(Container.DataItem, "Last_Name"))="",False,True)%>'/>
                            ,
                            <asp:Label ID="Label2" runat="server" Text='<%# Eval("First_Name") %>'  Visible='<%# IIF(CONVERT.ToString(DataBinder.Eval(Container.DataItem, "First_Name"))="",False,True)%>'/>
                            <asp:Label ID="Label3" runat="server" Text='<%# Eval("Prof_Designation") %>'  Visible='<%# IIF(CONVERT.ToString(DataBinder.Eval(Container.DataItem, "Prof_Designation"))="",False,True)%>'/>
                        </b>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label4" runat="server" Text='<%# Eval("Specialty") %>' Visible='<%# IIF(CONVERT.ToString(DataBinder.Eval(Container.DataItem, "Specialty"))="",False,True)%>'/>
                        <asp:Label ID="Label5" runat="server" Text='<%# Eval("[Specialty2]") %>' />
                        <br />
                        <asp:Label ID="Label6" runat="server" Text='<%# Eval("Address") %>'  Visible = '<%# IIF(Convert.ToString(DataBinder.Eval(Container.DataItem, "Address"))="",False,True) %>'/>
                        <br />
                        <asp:Label ID="Label7" runat="server" Text='<%# Eval("Address2") %>' Visible = '<%# IIF(Convert.ToString(DataBinder.Eval(Container.DataItem, "Address2"))="",False,True) %>'/>
                        <br />
                        <asp:Label ID="Label8" runat="server" Text='<%# Eval("City") %>' Visible = '<%# IIF(Convert.ToString(DataBinder.Eval(Container.DataItem, "City"))="",False,True) %>'/>
                        ,
                        <asp:Label ID="Label9" runat="server" Text='<%# Eval("State") %>' Visible = '<%# IIF(Convert.ToString(DataBinder.Eval(Container.DataItem, "State"))="",False,True) %>'/>
                        ,
                        <asp:Label ID="Label10" runat="server" Text='<%# Eval("Zip") %>' Visible = '<%# IIF(Convert.ToString(DataBinder.Eval(Container.DataItem, "Zip"))="",False,True) %>'/>
                        <br />
                        <asp:Label ID="Label11" runat="server" Text='<%# Eval("Phone") %>' Visible = '<%# IIF(Convert.ToString(DataBinder.Eval(Container.DataItem, "Phone"))="",False,True) %>'/>
                        <br />
                        <asp:Label ID="Label12" runat="server" Text='<%# Eval("Fax") %>' Visible = '<%# IIF(Convert.ToString(DataBinder.Eval(Container.DataItem, "Fax"))="",False,True) %>'/>
                        <br />
                        <asp:Label ID="lblId1" runat="server" Visible="false" Text='<%# Eval("Id") %>' />
                        <asp:CheckBox ID="CheckBoxPrintProvider1" runat="server" Text="Print this Provider" AutoPostBack="true" EnableViewState="true" />
                        <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: 17px;" width="98%"
                align="center">
                <tr>
                    <td style="margin-top: 17px">
                        <b>Matching Providers </b>
                    </td>
                    <br />
                    <td>
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td>
                        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="printButton1" 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="groupPlaceholder1" 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 [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]"
        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" DataKeyNames="ID">
        <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:Label ID="lblId2" runat="server" Visible="false" Text='<%# Eval("Id") %>' />
                        <asp:CheckBox ID="CheckBoxPrintProvider2" 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>
           
            <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:Label ID="lblId2" runat="server" Visible="false" Text='<%# Eval("Id") %>' />
                        <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; margin-right: 17px;" width="98%"
                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>
                        &nbsp;
                        <asp:LinkButton ID="LinkButton4" runat="server" CommandName="Sort" CommandArgument="City">City</asp:LinkButton>
                        &nbsp;
                        <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>

     </ContentTemplate>
    </asp:UpdatePanel>
    <br />
</asp:Content>






code Behind

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
Imports System.Collections


Public Class ProviderSearch
    Inherits System.Web.UI.Page


    Dim cBoxSelections As New List(Of String)()


    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

    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


        '####  First We want to pull all providers #####'

 
        If specialityDropDown.SelectedValue = "All" Then

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


        ElseIf specialityDropDown.SelectedValue = "All" And providerTextBox.Text <> "" Then
            ' Show me all doctors with that name
            Dim sql3 As String
            sql3 = "SELECT [Id],[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 + "%'  "
            AccessDataSource3.SelectCommand = sql3
            ListView1.Visible = False
            ListView2.Visible = True
            ListView2.DataBind()

        End If

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

            ' Show All Results 
            Dim sql As String
            sql = "SELECT [Id],[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 + "%'  "
            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 ###################################

    ' First we create the function for Listview1 

    Protected Sub ListView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ListView1.ItemCommand

        Dim myButtonPrint1 As Button = CType(ListView1.FindControl("printButton1"), Button)
        If e.CommandSource Is myButtonPrint1 Then
            Dim recordsId As New List(Of String)
            For Each lvi1 As ListViewItem In ListView1.Items
                Dim chb1 As CheckBox = lvi1.FindControl("CheckBoxPrintProvider1")

                If chb1.Checked = True Then
                    Dim param1 As String
                    param1 = DirectCast(lvi1.FindControl("lblId1"), Label).Text
                    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


    Protected Sub ListView2_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ListView2.ItemCommand

        Dim myButtonPrint2 As Button = CType(ListView2.FindControl("printButton2"), Button)
        If e.CommandSource Is myButtonPrint2 Then
            Dim recordsId As New List(Of String)
            For Each lvi2 As ListViewItem In ListView2.Items
                Dim chb2 As CheckBox = lvi2.FindControl("CheckBoxPrintProvider2")
                If chb2.Checked = True Then
                    Dim param1 As String
                    param1 = DirectCast(lvi2.FindControl("lblId2"), 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


    Protected Sub ListView1_PagePropertiesChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.PagePropertiesChangingEventArgs) Handles ListView1.PagePropertiesChanging
        Dim checksId As New List(Of String)
        For Each lvi1 As ListViewItem In ListView1.Items
            Dim chb1 As CheckBox = lvi1.FindControl("CheckBoxPrintProvider1")

            If chb1.Checked = True Then
                Dim paramCheck As String
                paramCheck = chb1.UniqueID
                checksId.Add(paramCheck)

            End If
        Next

        ' Store in session to be pulled out in the Printable Page
        Session("SessionchecksId") = checksId



    End Sub

    Protected Sub ListView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewSortEventArgs) Handles ListView1.Sorting
        For Each lvi As ListViewDataItem In ListView1.Items
            Dim chkSelect As CheckBox = DirectCast(lvi.FindControl("CheckBoxPrintProvider1"), CheckBox)
            If (((chkSelect) IsNot Nothing)) Then
                Dim ID As Integer = Convert.ToInt32(ListView1.DataKeys(lvi.DisplayIndex).Value)

                'Check if the ID is already there
                If (chkSelect.Checked AndAlso Not Me.IDs.Contains(ID)) Then
                    Me.IDs.Add(ID)
                ElseIf (Not chkSelect.Checked AndAlso Me.IDs.Contains(ID)) Then
                    Me.IDs.Remove(ID)
                End If
            End If
        Next
    End Sub


    Protected Sub ListView1_ItemDataBound(sender As Object, e As ListViewItemEventArgs)
        Dim lvi As ListViewDataItem = DirectCast(e.Item, ListViewDataItem)
        If lvi.ItemType = ListViewItemType.DataItem Then
            ' Get each checkbox Listview Item on DataBound
            Dim chkSelect As CheckBox = DirectCast(lvi.FindControl("CheckBoxPrintProvider1"), CheckBox)

            ' Make sure we're referencing the correct control
            If (chkSelect IsNot Nothing) Then
                ' If the ID exists in our list then check the checkbox
                Dim ID As Integer = Convert.ToInt32(ListView1.DataKeys(lvi.DisplayIndex).Value)
                chkSelect.Checked = Me.IDs.Contains(ID)
            End If
        End If
    End Sub

    Private ReadOnly Property IDs() As List(Of Integer)
        Get
            If Me.ViewState("IDs") Is Nothing Then
                Me.ViewState("IDs") = New List(Of Integer)()
            End If
            Return DirectCast(Me.ViewState("IDs"), List(Of Integer))
        End Get
    End Property


    Protected Function Selected(sender As Object) As [Boolean]
        Dim flag As [Boolean] = False
        Dim ID As String = Convert.ToString(sender)
        If Not String.IsNullOrEmpty(ID) Then
            flag = cBoxSelections.Exists(Function(item) item.Equals(ID))
        End If
        Return flag
    End Function


End Class

Open in new window

0
Comment
Question by:TonyReba
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 13

Expert Comment

by:Rick
ID: 37739761
Have you looked at this?
0
 
LVL 9

Author Comment

by:TonyReba
ID: 37739972
Yes,  but i need for listview.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 37743777
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question