Yazı Font Küçült Yazı Font Büyült

ListView  QueryStringField Alanını Kullanarak Sayfalama

 

Merhaba arkadaşlar, bu makalemizde ListView nesnemizi web adresinde belirtiğimiz sayfa no ya göre sayfalama yapacağız.

Configure ListView dan ListView nesnesinin Style ni belirleyin. (Şekil 1)

 

Resim1

Şekil 1

 

Sayfanıza Eklediğiniz DataPager nesnesinde Kontrol edeğeceğiniz nesneyi (PagerControlID) ListView seçin. Her sayfada ne kadar kayıt göstereceğimizide PageSize özelliğinden belirleyin. (Şekil 2)

 

Resim2

Şekil 2

 

Şimdi de DataPager nesnesine QueryStringField="sayfa_no" özelliğini olacak şekilde belirleyin. Adres kısmındaki Default.aspx?sayfa_no=11 kısmındaki sayfa_no bilgisini böylece almış olacağız.

 

Resim3

Şekil 3

 

Resim4

Şekil 4

 

Default.aspx

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

   

        <asp:ListView ID="ListView1" runat="server" DataKeyNames="ProductID"

            DataSourceID="AccessDataSource1">

            <AlternatingItemTemplate>

                <tr style="background-color: #FFFFFF;color: #284775;">

                    <td>

                        <asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' />

                    </td>

                    <td>

                        <asp:Label ID="ProductNameLabel" runat="server"

                            Text='<%# Eval("ProductName") %>' />

                    </td>

                    <td>

                        <asp:Label ID="UnitPriceLabel" runat="server" Text='<%# Eval("UnitPrice") %>' />

                    </td>

                </tr>

            </AlternatingItemTemplate>

            <EditItemTemplate>

                <tr style="background-color: #999999;">

                    <td>

                        <asp:Button ID="UpdateButton" runat="server" CommandName="Update"

                            Text="Update" />

                        <asp:Button ID="CancelButton" runat="server" CommandName="Cancel"

                            Text="Cancel" />

                    </td>

                    <td>

                        <asp:Label ID="ProductIDLabel1" runat="server"

                            Text='<%# Eval("ProductID") %>' />

                    </td>

                    <td>

                        <asp:TextBox ID="ProductNameTextBox" runat="server"

                            Text='<%# Bind("ProductName") %>' />

                    </td>

                    <td>

                        <asp:TextBox ID="UnitPriceTextBox" runat="server"

                            Text='<%# Bind("UnitPrice") %>' />

                    </td>

                </tr>

            </EditItemTemplate>

            <EmptyDataTemplate>

                <table runat="server"

                    style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">

                    <tr>

                        <td>

                            No data was returned.</td>

                    </tr>

                </table>

            </EmptyDataTemplate>

            <InsertItemTemplate>

                <tr style="">

                    <td>

                        <asp:Button ID="InsertButton" runat="server" CommandName="Insert"

                            Text="Insert" />

                        <asp:Button ID="CancelButton" runat="server" CommandName="Cancel"

                            Text="Clear" />

                    </td>

                    <td>

                        &nbsp;</td>

                    <td>

                        <asp:TextBox ID="ProductNameTextBox" runat="server"

                            Text='<%# Bind("ProductName") %>' />

                    </td>

                    <td>

                        <asp:TextBox ID="UnitPriceTextBox" runat="server"

                            Text='<%# Bind("UnitPrice") %>' />

                    </td>

                </tr>

            </InsertItemTemplate>

            <ItemTemplate>

                <tr style="background-color: #E0FFFF;color: #333333;">

                    <td>

                        <asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' />

                    </td>

                    <td>

                        <asp:Label ID="ProductNameLabel" runat="server"

                            Text='<%# Eval("ProductName") %>' />

                    </td>

                    <td>

                        <asp:Label ID="UnitPriceLabel" runat="server" Text='<%# Eval("UnitPrice") %>' />

                    </td>

                </tr>

            </ItemTemplate>

            <LayoutTemplate>

                <table runat="server">

                    <tr runat="server">

                        <td runat="server">

                            <table ID="itemPlaceholderContainer" 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 runat="server" style="background-color: #E0FFFF;color: #333333;">

                                    <th runat="server">

                                        ProductID</th>

                                    <th runat="server">

                                        ProductName</th>

                                    <th runat="server">

                                        UnitPrice</th>

                                </tr>

                                <tr ID="itemPlaceholder" runat="server">

                                </tr>

                            </table>

                        </td>

                    </tr>

                    <tr runat="server">

                        <td runat="server"

                            style="text-align: center;background-color: #5D7B9D;font-family: Verdana, Arial, Helvetica, sans-serif;color: #FFFFFF">

                        </td>

                    </tr>

                </table>

            </LayoutTemplate>

            <SelectedItemTemplate>

                <tr style="background-color: #E2DED6;font-weight: bold;color: #333333;">

                    <td>

                        <asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' />

                    </td>

                    <td>

                        <asp:Label ID="ProductNameLabel" runat="server"

                            Text='<%# Eval("ProductName") %>' />

                    </td>

                    <td>

                        <asp:Label ID="UnitPriceLabel" runat="server" Text='<%# Eval("UnitPrice") %>' />

                    </td>

                </tr>

            </SelectedItemTemplate>

        </asp:ListView>

        <asp:AccessDataSource ID="AccessDataSource1" runat="server"

            DataFile="~/App_Data/Northwind.mdb"

            SelectCommand="SELECT [ProductID], [ProductName], [UnitPrice] FROM [Products]">

        </asp:AccessDataSource>

        <br />

        <asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1"

         QueryStringField="sayfa_no" PageSize="5" >

        </asp:DataPager>

   

    </div>

    </form>

</body>

</html>

 

 Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek dileğiyle. Hoşçakalın. Bahadır ŞAHİN