Datagrid template asp net




















The following table lists the named parts for the DataGridColumnHeader element. The following table lists the visual states for the DataGridColumnHeader element. The following example shows how to define a ControlTemplate for the DataGrid control and its associated types.

For the complete sample, see Styling with ControlTemplates Sample. Skip to main content. This browser is no longer supported. Download Microsoft Edge More info. Contents Exit focus mode. Please rate your experience Yes No. Was this demo helpful? Feel free to share demo-related thoughts here. If you have technical questions, please create a support ticket in the DevExpress Support Center. Backend API. ID "gridContainer". ShowBorders true. Width AllowFiltering false.

AllowSorting false. Width 70 ; columns. FirstName ; columns. LastName ; columns. Position ; columns. BirthDate ; columns. Models; using DevExtreme. DataGrid; using DevExtreme. SampleData; using System; using System. Linq; using System. Mvc; namespace DevExtreme. DataGrid; using System; using System. Generic; namespace DevExtreme. He once bowled a perfect game of She has been selling DevAV products since She is expecting her first child in 6 months. Good Luck Olivia.

Her best marathon time is 4 hours. Go Greta. She loves to interact with staff so if you've not met her, be certain to say hi. Way to go Cindy! He is a classically trained musician and is a member of the Chamber Orchestra.

He does a great job as a member of our IT department. To accommodate this level of flexibility the GridView offers the TemplateField, which renders using a template. Furthermore, the TemplateField has a variety of templates that can be used to customize the rendering for different situations.

For example, the ItemTemplate is used by default to render the cell for each row, but the EditItemTemplate template can be used to customize the interface when editing data. In the preceding tutorial we saw how to customize the formatting based on the underlying data using the DataBound and RowDataBound event handlers. Another way to customize the formatting based on the underlying data is by calling formatting methods from within a template.

We'll look at this technique in this tutorial as well. For this tutorial we will use TemplateFields to customize the appearance of a list of employees. Specifically, we'll list all of the employees, but will display the employee's first and last names in one column, their hire date in a Calendar control, and a status column that indicates how many days they've been employed at the company.

In reporting scenarios where you need to use TemplateFields to customize the appearance, I find it easiest to start by creating a GridView control that contains just BoundFields first and then to add new TemplateFields or convert the existing BoundFields to TemplateFields as needed. Therefore, let's start this tutorial by adding a GridView to the page through the Designer and binding it to an ObjectDataSource that returns the list of employees.

These steps will create a GridView with BoundFields for each of the employee fields. Open the GridViewTemplateField. To remove these BoundFields you can:. Take a moment to view our progress in a browser. At this point you should see a table with a record for each employee and four columns: one for the employee's last name, one for their first name, one for their title, and one for their hire date.

Currently, each employee's first and last names are displayed in a separate column. It might be nice to combine them into a single column instead. To accomplish this we need to use a TemplateField. Both approaches net the same result, but personally I like converting BoundFields to TemplateFields when possible because the conversion automatically adds an ItemTemplate and EditItemTemplate with Web controls and databinding syntax to mimic the appearance and functionality of the BoundField.

The benefit is that we'll need to do less work with the TemplateField as the conversion process will have performed some of the work for us. Select the BoundField to convert from the list in the lower left corner and then click the "Convert this field into a TemplateField" link in the bottom right corner. After this change there's no perceptive difference in the Designer. This can be accomplished either by hand or through the Designer.

To do it by hand, simply add the appropriate declarative syntax to the ItemTemplate :. This will display the GridView's template editing interface. In this interface's smart tag is a list of the templates in the GridView. Since we only have one TemplateField at this point, the only templates listed in the drop-down list are those templates for the FirstName TemplateField along with the EmptyDataTemplate and PagerTemplate.

The EmptyDataTemplate template, if specified, is used to render the GridView's output if there are no results in the data bound to the GridView; the PagerTemplate , if specified, is used to render the paging interface for a GridView that supports paging. We need to change this so that this property is bound to the value of the LastName data field instead.

To accomplish this click on the Label control's smart tag and choose the Edit DataBindings option. This will bring up the DataBindings dialog box. From here you can select the property to participate in databinding from the list on the left and choose the field to bind the data to from the drop-down list on the right. The DataBindings dialog box allows you to indicate whether to perform two-way databinding.

Either approach is fine for this tutorial. Two-way databinding becomes important when inserting and editing data. For simply displaying data, however, either approach will work equally well. We'll discuss two-way databinding in detail in future tutorials. Take a moment to view this page through a browser. After these changes the GridView's declarative markup should look like the following:.



0コメント

  • 1000 / 1000