C # DataGrid Sets line font bold cell alignment based on the contents of a column

Source: Internet
Author: User

Recently a feature was made, and the DataGrid was grouped according to a column when it was displaying specific content.

After each grouping specific content, add a line to display the total information.

When querying data, union All is used to combine grouped data with detail data, using a sort that achieves the desired effect.

When binding the data, in order to make the total row more eye-catching, so the merge row is bold, the total column is centered.

Interface such as:

DataGrid Front Desk:

1<asp:datagrid id="dglist"Datakeyfield="ID"runat="Server"autogeneratecolumns="False"Onitemdatabound="Dglist_itemdatabound">2<Columns>3<asp:templatecolumn headertext="Column 1">4<ItemTemplate>5<asp:label id="Lab_cop_g_no"runat="Server"text='<% #Eval ("Cop_g_no")%>'></asp:Label>6</ItemTemplate>7</asp:TemplateColumn>

DataGrid Background ItemDataBound Method:

1 protected voidDglist_itemdatabound (Objectsender, DataGridItemEventArgs e)2         {3             if(E.item.itemtype = = ListItemType.Item | | e.item.itemtype = =ListItemType.AlternatingItem)4             {5Label Lab_cop_g_no = (label) E.item.findcontrol ("Lab_cop_g_no");6                 if(Lab_cop_g_no. Text = ="Total:")7                 {8E.item.font.bold =true;9 Ten((TableCell) lab_cop_g_no. Parent). HorizontalAlign =Horizontalalign.center; One                 } A             } -}

Judging by the contents of column 1, is "total:", row bold display E.item.font.bold = true;

The total is shown in the show ((TableCell) lab_cop_g_no. Parent). HorizontalAlign = Horizontalalign.center;
Recommended E.item.findcontrol This way of writing, the foreground uses template columns, so that the foreground adjustment column order does not affect the use of the background.

C # DataGrid Sets line font bold cell alignment based on the contents of a column

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.