How to change the page navigation bar of the DataGrid control to a style.
When the DataGrid control is used for paging, either the previous page, the next page, or all numbers are displayed. After making the control, you will not be able to see it, let alone common viewers. But how can we change it ??
In fact, it is not very difficult. First, let's look at what the DataGrid shows, which may be a bit eye-catching. Bytes
In the DataGrid, the pagination navigation bar is represented by a single row (tablerow). In this row (tablerow), there is only one column (tablecell ), all the buttons (linkburron) we see are controls in this column (tablecell ).The layout is: a hyperlink (linkburron), a space, a hyperlink (linkbutton), and a space... It is worth noting that all the stuff generated in ASP. NET is a control, so that space cannot be escaped. Therefore, if we want to change the style, we just need to change the controls in the tablecell.
To achieve changeTablecellThe purpose of the control, we also need to useItemcreatedEvent, written on msdn:
When an item in the DataGrid Control is created (whether during a round trip or when data is bound to the control ),ItemcreatedEvent.ItemcreatedEvents are usually used to controlDataGridThe content and appearance of the row in the control.
Well, let's see how it is implemented:
1. Add onitemcreated = "itemcreaged" in the DataGrid attribute ";
2. Add the following code
Void itemcreated (Object sender, datagriditemeventargs E)
{
Listitemtype type = E. Item. type; // listitemtype is enumeration, indicating that different items can be included in the List Control
If (type = listitemtype. pager)
{
Tablecell pager = (tablecell) E. Item. controls [0];
For (INT I = 0; I <pager. Controls. Count; I ++ = 2)
{
Object o = pager. controls [I];
If (O is linkbutton)
{
Linkbutton H = (linkbutton) O;
H. Text = "[" + H. Text + "]";
}
Else
{
Label L = (Label) O;
L. Text = "page" + L. Text + ";
}
}
}
}
The above code can implement a paging navigation bar different from the default style.