Solved

Listview Control Paging , Preserving the State Checkboxes

Posted on 2012-03-20
2
1,040 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now