Automatic number in controls such as DataGrid

xiaoxiao2021-03-06  116

Author: Unknown author please contact me speed

Serial number

content

1

Taye

2

Box

3

Glass

4

Starcraft

First, positive order

A, sopaging = false

<% # container.itemindex 1%>

It can be implemented, but more interesting methods is to use this method.

<% # this.dataGrid1.items.count 1%>

Maybe some people feel very strange why it is like this, not all the contracts .. But if you understand the binding process, it is easy to understand. [From above, it is binding in the itemcreated event. Items.count is just the current number] b, sopaging = "true" If your DataGrid supports paging, you can follow

<% # this.DataGrid1.CurrentPageIndex * this.DataGrid1.PageSize Container.ItemIndex 1%>

Second, reverse order

Serial number

content

4

Taye

3

Box

2

Glass

1

Starcraft

From the above, it is impossible to use this.DataGrid1.items.count - Container.itemindex 1 method, it is impossible to achieve a value and all the best in the case of 1 point. So we will get the data source. number

.CS

Private int rot = 0;

Protected int ROWSCOUNT

{

Get {return rowscount;}

Set {this.rowscount = value;

}

Private Void Page_Load (Object Sender, System.EventArgs E)

{

/ / Place the user code here to initialize the page

IF (! ispostback)

THIS.BINDDATA ();

}

Private void binddata () {

SqlConnection CN = New SQLCONNECTION ("Server = (local); database = northwind; uid = sa; pwd =");

String str = @ "Select Employees.employeeiD, Orders.employeID

From Employees Inner Join

ORDERS on Employees.employeeid = Orders.employeeid ";

SqldataAdapter Sqlda = New SqldataAdapter (STR, CN);

DataSet DS = New DataSet ();

Sqlda.fill (DS);

This.Rowscount = ds.tables [0] .rows.count;

THIS.DATAGRID1.DATASOURCE = DS;

THIS.DATAGRID1.DATABIND ();

}

.aspx

<% # Rowscount - DataGrid1.currentPageIndex * DataGrid1.pageSize - Container.Index%>

Of course, if it is not a paging, it is easier to implement.

转载请注明原文地址:https://www.9cbs.com/read-101704.html

New Post(0)