Change the style of the DataGrid tab bar

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.