Solved

Listview Control Paging , Preserving the State Checkboxes

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 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