在Listview

时间:2015-05-22 11:43:03

标签: c# asp.net listview refresh postback

在Listview中更改页面时,有什么方法可以防止重新加载整个网站?我的意思是,当我点击下一页按钮时,它再次重新加载整个网站...我可以在列表视图中转到下一页而不刷新所有内容吗?

提前致谢!

                                                                                         
    <div class="imageset">
    <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="ID">
        <AlternatingItemTemplate>
            <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl='<%# Eval("image", "{0}") %>' PostBackUrl='<%# Eval("ID", "~/oferta.aspx?cat=" + Request.QueryString["cat"] + "&id={0}") %>' Width="180px" Height="120px" CssClass="imagebtn" CommandName="Choose" />
        </AlternatingItemTemplate>
        <ItemTemplate>
            <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%# Eval("image", "{0}") %>' PostBackUrl='<%# Eval("ID", "~/oferta.aspx?cat=" + Request.QueryString["cat"] + "&id={0}") %>' Width="180px" Height="120px" CssClass="imagebtn" CommandName="Choose" />
        </ItemTemplate>
    </asp:ListView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [P_Produkty] WHERE ([kategoria] = @kategoria)">
        <SelectParameters>
            <asp:QueryStringParameter Name="kategoria" QueryStringField="cat" Type="String" />
        </SelectParameters>
        </asp:SqlDataSource>
    </div>
    <div class="bottombtn">
        <asp:DataPager ID="DataPager2" runat="server" PagedControlID="Listview1" PageSize="3">
            <Fields>
                <asp:NextPreviousPagerField ButtonType="Image" FirstPageText="" LastPageText="" NextPageImageUrl="~/images/arrowbtndown.png" NextPageText="" PreviousPageText="" ShowPreviousPageButton="False" ButtonCssClass="bottombtn" />
            </Fields>
        </asp:DataPager>
    </div>

1 个答案:

答案 0 :(得分:0)

<asp:ListView>包装在<asp:UpdatePanel>中,并将ListView的PageIndexChanged事件添加为UpdatePanel的aSyncPostBackTrigger。 像这样:

<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
<asp:ListView `ID="listview1" runat="server" DataSourceID="SqlDataSource1">
//columns
</asp:ListView>
</ContentTemplate>
<aSyncPostBackTrigger ControlID="listview1" EventName="PageIndexChanged" />
</UpdatePanel>`