Solved

Listview Control Paging , Preserving the State Checkboxes

Posted on 2012-03-20
2
1,052 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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