ASP.NET筆記之 行命令處理與分頁詳解

來源:互聯網
上載者:User

1、行命令處理

(1、 後台代碼:操作行

//如果是來自html響應中的該函數操作
if(e.CommandName=="addAge"){

//取得行號
int index=((ListViewDataItem)e.Item)DispalyIndex;
//取得當前操作行的主索引值
//DataKeys存的是所有ID,取的是第index個ID
Guid id=(Guid)ListView1.DataKeys[index].Value;
表Adapter adapter=new 表Adapter();
adpter.自訂資料庫函數addAge;
//資料繫結
ListView.DataBing();
}

(2、排序
CommandName="Sort"
CommandArgument="ID"
內部排序,效率較低

2、DataPager 分頁

PageControlID:給哪個ListView分頁

進階分頁:

查詢子查詢
select* from
(Select id,name,age,row_number() over(order by id)rownum from T_Users)t
where t.rownum>11and t.rownum<20

3、高效分頁:


(1、資料庫方法:

//擷取本頁的行數
開始的行數:startRowIndex
開始加本頁的行數:startRowIndex+maximumRows

//資料庫方法:GetCount
select Count(*)from T_Users

//資料庫方法名:QueryCount
select* from

select Id ,Name,Gender,Row_Number() over(order by Id)rownum FROM dbo.T_User
)t
where t.rownum>@startRowIndex and t.rowRow<=@startRowIndex+@maximumRows

由於startRowIndex+maximumRows兩個參數不會幫我們產生,需要我們自己手動添加。

(2、頁面

**不要<SelectParameters>
**增加一個SelectCountMethod="QueryCount"設定取得行數的方法
而SelectMethod="GetPageData"是取得分頁資訊
而EnablePaging="true"
**先按正常流程配置ListView的objectDataSource,讓ListVIew自動產生
再去配置分頁資料來源

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.