關於DataGrid等控制項中的自動編號

2022-01-28 20:29:26 字數 1518 閱讀 9005

序號內容

1taye

2box

3glass

4starcraft

一、正序

a、

allowpaging

=false

情況下<%# container.itemindex + 1%>

itemtemplate>

asp:templatecolumn>

asp:datagrid>

就可以實現

不過更有趣的方法是使用這個方法

<%# this.datagrid1.items.count + 1%>

itemtemplate>

asp:templatecolumn>

asp:datagrid>

也許有些人會覺得很奇怪為什麼

items.count

會這樣,而不是出來全部總合

..但如果你了解繫結的過程時就容易理解.[

從上面來看就是在

itemcreated

事件中進行繫結所以得到的

items.count

剛好是當前的序號]b

、allowpaging

="true"

下如果你

datagrid

支援分頁則

可以如下

<%# this.datagrid1.currentpageindex * this.datagrid1.pagesize + container.itemindex + 1%>

itemtemplate>

asp:templatecolumn>

asp:datagrid>

二、倒序的方法

序號內容

4taye

3box

2glass

1starcraft

由上面可以知道使用

this.datagrid1.items.count -

container.itemindex

+ 1方法是不可能實現的,得到值而且全會為

1分頁的情況下更是一樣

.所以一開始我們就要取得資料來源的行數

.csprivate

int rowscount = 0;

protected

int rowscount

set}

private

void

page_load(object sender, system.eventargs e)

private

void

binddata()

.aspx

<%# rowscount - datagrid1.currentpageindex * datagrid1.pagesize - container.itemindex %>

itemtemplate>

asp:templatecolumn>

asp:datagrid>

當然如果是不是分頁的情況一下更容易實現了.

關於DataGrid等控制項中的自動編號

序號內容1 taye 2box 3glass 4starcraft 一 正序 a allowpaging false情況下 container.itemindex 1 itemtemplate asp templatecolumn asp datagrid 就可以實現 不過更有趣的方法是使用這個方法...

關於DataGrid等控制項中的自動編號

序號內容 1taye 2box 3glass 4starcraft 一 正序 a allowpaging false情況下 container.itemindex 1 itemtemplate asp templatecolumn asp datagrid 就可以實現 不過更有趣的方法是使用這個方法...

WPF中DataGrid控制項

設定不可自動拉伸寬度 datagrid.canuserresizecolumns false 第一列不可見 datagrid.headersvisibility datagridheadersvisibility.column 設定不可自動拉伸高度 datagrid.canuserresizerow...