Solved

Listview Control Paging , Preserving the State Checkboxes

Posted on 2012-03-20
2
1,079 Views
Last Modified: 2012-03-24
Hello Everyone,

I have a question regarding the listview control paging and preserving the state of the items on page change.I am using listview control and datapager control to achieve paging in the listview control.I use the listview to display list of providers a label with name and the checkbox to select..

However, I am unable to preserve the selection of answers between the page changes..


My Live site is:
www.rgvpreferred.com

And the my code is below , thanks in advance.

<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>




  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

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
2 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 37743768
0
 
LVL 9

Author Comment

by:TonyReba
ID: 37744151
Yes Actually I have tried 2 and 3rd, the first one is for gridview,  I am not sure if it has to do with the way the page is post back when it goes one page to another , please see code.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

717 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