DataGrid automatic number

xiaoxiao2021-03-05  21

There are a lot of people in the forum to ask questions about DataGrid.

Serial number

content

1

Taye

2

Box

3

Glass

4

Starcraft

First, positive order

A, sopaging = false

<% # Container.itemindex 1%>

It can be realized

But more interesting methods is to use this method

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

Maybe some people will feel very strange why items.count will be like this, not all the contracts .. But if you understand the binding process, it is easy to understand.

[From the above, it is binding in the itemcreated event, so the items.count just is the current number]

B, allowpaging = "true" under

If you have DataGrid supports paging, you can follow

<% # this.datagrid1.currentpageindex * this.dataGrid1.pageSize Container.Index 1%>

two,

Reverse method

Serial number

content

4

Taye

3

Box

2

Glass

1

Starcraft

From the above you can know

This.DataGrid1.items.count - Container.itemindex 1 method is impossible to achieve value and all meet

The same is true in the case of paging. So we will get the number of rows of data sources.

.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.employeid, Orders.employeeiD

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-36027.html

New Post(0)