Asp.net template field visible




















Copy Code. Posted Jul pm jiji Add a Solution. Top Rated Most Recent. Accept Solution Reject Solution. Try: C.

Posted Jul pm Priyanka Member Dec am. Solution 2 helps me. Its running absolutely what i wanted. SathishRam Dec am. Tan Q!!!!! DataRow e. Posted Jul am vikranthkatta. Posted Jul pm chimcham. Posted Feb am aolork. Richard Deeming Feb pm. And your "solution" suffers from the same problem as the code in the question.

Add your solution here. The TemplateField object is displayed differently depending on the data-bound control in which it is used. For example, the GridView control displays a TemplateField object as a column, and the DetailsView control displays it as a row. You can define a custom template for the different parts of the TemplateField object using the templates listed in the following table.

You can hide a TemplateField object in a data-bound control by setting the Visible property to false. As an alternative to defining a custom HeaderTemplate or FooterTemplate template, you can customize the header and footer sections of a TemplateField object by setting other properties of the TemplateField object.

To display a caption in the header or footer sections, set the HeaderText or the FooterText property, respectively. Instead of displaying text in the header section, you can display an image by setting the HeaderImageUrl property.

The header section can be hidden in the TemplateField object by setting the ShowHeader property to false. Some data-bound controls such as the GridView control can show or hide only the entire header section of the control.

These data-bound controls do not support the ShowHeader property for an individual bound field. To show or hide the entire header section of a data-bound control, use the control's ShowHeader property if available.

You also can customize the appearance of the TemplateField object font color, background color, and so on by setting the style properties for the different parts of the field.

The following table lists the different style properties. Initializes a new instance of the TemplateField class. Gets or sets text that is rendered as the AbbreviatedText property value in some controls.

Gets or sets the template for displaying the alternating items in a TemplateField object. Gets a reference to the data control that the DataControlField object is associated with. Gets the style of any Web server controls contained by the DataControlField object.

Gets or sets a value indicating whether the value that the TemplateField object is bound to should be converted to null if it is Empty. Gets a value indicating whether a data control field is currently viewed in a design-time environment.

Gets or sets the template for displaying an item in edit mode in a TemplateField object. Gets or sets the template for displaying the footer section of a TemplateField object. Gets or sets the template for displaying the header section of a TemplateField object.

Gets or sets the template for displaying an item in insert mode in a TemplateField object. Gets a value indicating whether the DataControlField object is visible when its parent data-bound control is in insert mode. Gets a value indicating whether the DataControlField object is saving changes to its view state. Gets a dictionary of state information that allows you to save and restore the view state of a DataControlField object across multiple requests for the same page.

Creates a duplicate copy of the current DataControlField -derived object. Copies the properties of the current TemplateField -derived object to the specified DataControlField object. Creates a new TemplateField object. Extracts the value of the data control fields as specified by one or more two-way binding statements DataBind from the current table cell and adds the values to the specified IOrderedDictionary collection.

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:. Displaying a data field value as text in a GridView is as simple as using a BoundField. For certain scenarios, however, the data is best expressed using a particular Web control instead of just text.

Such customization of the display of data is possible with TemplateFields. For example, rather than display the employee's hire date as text, we could show a calendar using the Calendar control with their hire date highlighted. Simply go to the GridView's smart tag and click the Edit Columns link, bringing up the Fields dialog box. To replace the text with a Calendar control, edit the template by removing the Label and adding a Calendar control.

Next, delete the Label control and drag a Calendar control from the Toolbox into the template editing interface. However, the employee's actual HiredDate value is not set anywhere in the Calendar control, causing each Calendar control to default to showing the current month and date. From the Calendar control's smart tag, choose Edit DataBindings. The Calendar control's selected date need not necessarily be visible.

For example, a Calendar may have August 1 st , as the selected date, but be showing the current month and year. The selected date and visible date are specified by the Calendar control's SelectedDate and VisibleDate properties. Since we want to both select the employee's HiredDate and make sure that it's shown we need to bind both of these properties to the HireDate data field.

When viewing the page in a browser, the calendar now shows the month of the employee's hired date and selects that particular date. Contrary to all the examples we've seen thus far, for this tutorial we did not set EnableViewState property to false for this GridView.

The reason for this decision is because clicking the dates of the Calendar control causes a postback, setting the Calendar's selected date to the date just clicked.



0コメント

  • 1000 / 1000