SortExpression, fields[i]. HeaderText, this. Equals "id", StringComparison. OnRowCreated e ; if e. OnRowDataBound e ; if e. DataSource as DataView; if dv! Empty; string ICallbackEventHandler. ClientState System. Instance System. NonPublic ; mi. Invoke this.
GetProperty "ClientState", System. GetValue this. Page, null. LoadXml eventArgument. Empty; if doc. InnerText; switch doc. InnerText; Sort sortExpression. Split ' ' [0]. Trim , sortExpression. Split ' ' [1]. Equals "ASC"? Ascending : SortDirection. InnerText; this. Tony Gayter Rate me:. Please Sign up or sign in to vote.
Copy Code. Tony Gayter. Web Developer. Tony Gayter Aug Awaidus Bin Asim Aug Tony Gayter Sep Go to top. Layout: fixed fluid. 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. If the GridView's view state is disabled, however, on each postback the GridView's data is rebound to its underlying data source, which causes the Calendar's selected date to be set back to the employee's HireDate , overwriting the date chosen by the user.
For this tutorial this is a moot discussion since the user is not able to update the employee's HireDate. It would probably be best to configure the Calendar control so that its dates are not selectable. Regardless, this tutorial shows that in some circumstances view state must be enabled in order to provide certain functionality.
A third use of TemplateFields is in displaying metadata about the GridView's underlying data. In addition to showing the employees' hire dates, for example, we might also want to have a column that displays how many total days they've been on the job. Yet another use of TemplateFields arises in scenarios when the underlying data needs to be displayed differently in the web page report than in the format it's stored in the database.
Imagine that the Employees table had a Gender field that stored the character M or F to indicate the sex of the employee. When displaying this information in a web page we might want to show the gender as either "Male" or "Female", as opposed to just "M" or "F". Both of these scenarios can be handled by creating a formatting method in the ASP. NET page's code-behind class or in a separate class library, implemented as a static method that is invoked from the template.
Such a formatting method is invoked from the template using the same databinding syntax seen earlier. The formatting method can take in any number of parameters, but must return a string.
This returned string is the HTML that is injected into the template. To illustrate this concept, let's augment our tutorial to show a column that lists the total number of days an employee has been on the job. This formatting method will take in a Northwind. Search related threads. Remove From My Forums. Asked by:. Archived Forums. Web Forms Data Controls. Sign in to vote. User posted Hi, I have a grid which have 3 fixed columns and others are autogenerated column depends upon the resultset.
Tuesday, July 29, AM. User posted Hi amitsplash , I have tested this scenario use one hr element and it performs different from what you said. Thursday, July 31, AM.
0コメント