本文介绍了与asp.net gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对网格视图有疑问..我有一个缺少1条记录的数据库..假设如果我想一次检索1条缺少数据库的记录,那么数据库性能将会下降..我想检索这些记录基于页面大小..假设我按第一页按钮仅从数据库调用前100条记录,而我按第二页按钮仅调用101-200条记录,我的页面大小为100.谢谢

I have a doubt on grid-view.. i have a database with 1 lack records.. suppose if i want to retrieve 1 lack database records at a time the database performance will be decreasing.. i want to retrieve the records based on the page size.. suppose my page size is 100 if i press first page button call first 100 records only from database..and i press 2nd button call 101-200 records only..can any one help for this problem.. thank you

推荐答案

<asp:gridview id="DgTest" runat="server" autogeneratecolumns="False" xmlns:asp="#unknown">
            Width="100%" AllowSorting="True" OnRowCommand="DgTest_RowCommand"
            OnRowDataBound="DgTest_RowDataBound" AllowPaging="True"
            onpageindexchanging="DgTest_PageIndexChanging" CaptionAlign="Right"> </asp:gridview>



将PageIndexChanging事件创建为



Create PageIndexChanging event as

protected void DgTest_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            DgTest.PageIndex = e.NewPageIndex;
            Populate();
        } 





private void Populate()
        {
            //Code To get datasource to Databind
        }


不要忘记设置属性Pagesize = 100


Dont forget to set property Pagesize=100



SELECT TOP numberofrecordsyouwanttotake
    [yourColumns...]
FROM tableName
WHERE yourIDColumn NOT IN (
    SELECT TOP numberofrecordsyouwanttoskip
        yourIDColumn
    FROM tableName
    ORDER BY yourOrderColumn
)
ORDER BY yourOrderColumn




谢谢!!!




Thanks!!!


这篇关于与asp.net gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 14:33