DataGrid Usage Tips Summary - Personalized Page and Complex Headers

xiaoxiao2021-03-06  42

When using DataGrid, there will always have a variety of needs, and the most used in the project deal with the database will be DataGrid, and Microsoft sometimes does that, so I need us. I have been implemented.

DataGrid custom paging navigation

No other third-party controls are required, on the basis of DataGrid's own paging. Effect:

Let DataGrid's own paging achieve this effect [1] [2] [3] [4] [5] [6]

Let DataGrid's own paging achieve this effect [1] [2] [3] [4] [5] [6]

private void grid_ItemCreated (object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {if (e.Item.ItemType == ListItemType.Pager) {foreach (Control c in e.Item.Cells [0] .Controls) { IF (c is label) // Current page {label lblpage = (label) c; // lblpage.forecolor = system.drawing.colortranslator.fromhtml ("# e

78A

29 "); // # e

78A

29, # ff0000 // lblpage.font.bold = true; lblpage.text = "[

78A

29> lblpage.text " ]"; // (((Label )c ).ForeColor = system.drawing.color.green; // Break;} if (c is LinkButton) // Link Other Pages {LinkButton LinkButton = (LinkButton) C; LinkButton.Text = "[" LinkButton.Text "]";}}}}

Auto number in controls such as DataGrid:

Add a template column:

Creating complex heads in DataGrid

Method 1: Implement with Table

"); strText.Append (" "); Strtext.Append (""); strText.Append ("
< / TD> Form Top

Form bottom end

Method 2: Dynamic generating head

Generate a double sheet head: private void grid_itemdatabase (Object sender, system.web.ui.webcontrols.dataGriditeMeventArgs e) {

IF (E.Item.itemType == ListItemType.Header) {// E.Item.cells [0] .COLUMNSPAN = 1; // This is the first column of cross-column StringBuilder Strtext = New StringBuilder (); strText. Append ("// "); strText.Append ("

Life illumination "); strText.Append (" General lighting " ); StrText.Append (" Work 25 "); Strtext.Append (" Agriculture "); Strtext.Append (" Total "); strText.Append (" "); strText.Append ("
" E.Item.cells [ 0] .text); E.Item.cells [0] .Text = start.toTOString ();

}

}

The entire header content:

E.Item.cells [0] .Text = content added up the style of the header.

Life lighting, general lighting, industrial agriculture

Generate a three-story head:

IF (E.Item.itemType == ListItemType.Header) {StringBuilder Strtext = new stringbuilder (); stringbuilder (); strText.Append (""); strText.Append ("

The month "); StrText.Append (" ");

Strtext.Append ("

Resident "); Strtext.Append (" General "); Strtext .Append (" Work 25 "); Strtext.Append ("");

Strtext.Append ("

" E.Item.cells [0] .text); E.Item.cells [0] .text = strText.toString (); }

Working industry in the month

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

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.033, SQL: 9