Change the style of the DataGrid paging bar

zhaozj2021-02-16  60

How to make the Paging navigation strip of the DataGrid control.

When you use the DataGrid control to make a pagination, you or the next page, next page, or all numbers, you will see you, don't mention ordinary browsing. But how can I change it? ?

In fact, it is not very difficult, first look at what DataGrid is displayed, so it may be a bit eyebrow. ¢

In DataGrid, the paging navigation bar is manifested in a table, in this line (TableRow), only one column (Tablecell), all of the digital hyperlink button (Linkburron) is this column (TableCell), the layout inside is: a hyperlink, a space, one more linkbutton, and then pick a space. . . It is worth mentioning that all stuffs generated in Asp.net are controls, so that space can't escape. So, we want to change the style, it is to change the control inside the TableCell.

In order to change the purpose of changing the control inside Tablecell, we also use the itemcreated event, write on the MSDN:

When you create an item in the DataGrid control (whether it is binding to the control in the round trip to the control), you will trigger an itemcreated event. The itemcreated event is usually used to control the contents and appearances of the line in the DataGrid control.

Ok, let's take a look at how the specific is achieved:

1. Add OnItemCreated = "itemcreaged" in the properties of DataGrid; "ITEMCREAGED"

2. Plus in the code below

Void itemcreated (Object Sender, DataGriditeMeventargs E)

{

ListiteMType type = E.Item.Type; // ListiteMType is an enumeration, indicating that you can include different items in the list control

IF (Type == ListItemType.pager)

{

Tablecell Pager = (TableCell) E.Item.controls [0];

For (int i = 0; i

{

Object o = pager.controls [i];

IF (o is linkbutton)

{

LinkButton H = (LinkButton) O;

H.Text = "[" H.Text "]";

}

Else

{

Label L = (label) O;

L.Text = "No. L.Text " Page ";

}

}

}

}

These codes can achieve paging navigation bars different from the default style.

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

New Post(0)