Hot questions about the DataGrid Web control

Source: Internet
Author: User
Tags eval header
Datagrid|web| Control | issues

Customizing the appearance of columns in display and edit mode

By default, the DataGrid displays data with a preset size column. When you set the row to edit mode, the control displays all editable data in the textbox, regardless of the type of data.

If you want to customize the contents of a column, set the column as a template column, and the template column works like an item template in a dataist or repeater control. The difference is that you define the appearance of the column as not the appearance of the row.

When defining a template column, you can specify the following template types:

① uses item templates to customize the general appearance of data.

② Use the Edit item template to specify the display of the column when you set the row to edit mode. It allows you to specifically set a control instead of the default textbox in edit mode.

The ③header template and the footer template allow you to customize the header and footer of the control separately. (The tail of the table is displayed only if the DataGrid's Showfoot property is set to true.) )

The following example is an HTML syntax for a template column that displays Boolean data. Both the item template and the Edit template use a checkbox to display the value. The checkbox in the item template is not available and cannot be checked by the consumer, and the checkbox in the Edit item template seems to allow the user to select it.

<columns>

<asp:templatecolumn headertext= "Discontinued" >

<ItemTemplate>

<asp:checkbox runat = "server" Enabled=false name= "Checkbox 2"

id= "checkbox 2"

Checked= ' <% #DataBinder. Eval (Container, "dataltem.discontinued")%> ' >

</asp:Checkbox>

</ItemTemplate>

<EditltemTemplate>

<asp:checkbox

runat= "Server" name= "checkbox 2" id= "checkbox 2"

Checked= ' <% #DataBinder. Eval (Container, "dataitem.discontinued")%> ' >

</asp:Checkbox>

</EditltemTemplate>

</asp:TEmplateColumn>

</Columns>

Note: If you use a checkbox in an edit template, realize that at run time, the table item cell actually contains a few LiteralControl controls other than the checkbox itself, and any time you know the ID of the control you want to value, Use the FindControl method to create a reference to it, rather than using it in a collection of cells or a specific index value of a control collection.

CheckBox CB;

cb= (checkbox) E.item.findcontrol ("checkbox 2"), in vs. You can use the DataGrid's property Builder to create a template column. and use the template editor to specify its appearance, in the column selection of the Properties window page, select the column and click the Convert column to template column at the bottom, close the Properties window, right-click the DataGrid, and select Edit Template, and then, You can drag controls from the toolbox to the template, or you can add static text.

(unfinished)



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.