Automatic number in controls such as DataGrid

xiaoxiao2021-03-06  43

There are a lot of people on the Internet to ask questions about DataGrid, but I have already replied several times in the forum, but I still have a question.

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 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 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 count = 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-74909.html

New Post(0)