In Asp.net 2.0, if you want to display data in the binding column, such as the date format, the following method cannot be used.
Dataformatstring = "{0: M-dd-yyyy }"
Headertext = "creationdate"/>
The main reason is that the htmlencode attribute is set to true by default, which has prevented XSS attacks and is used for security reasons. Therefore, there are two solutions:1,Dataformatstring = "{0: M-dd-y
DataGrid is an important control in ASP. NET. It is often made into a paginated and sortable DataGrid, and sometimes the selection function needs to be added. These are frequently used methods, which are actually relatively simple.
Design Concept:For convenience, we connect to the orders table of the northwind database of SQL Server 2000 to obtain the data view of this table from the database. Use the DataGrid sortcommand event to sort data. Add the checkbox control to a template column for
String in dataformatstring formatDataformatstring = "{0: Format String }"
{0} In dataformatstring represents the data itself, while the format string after the colon represents the format they want to display the data;
Number and currency format:After the specified format symbol, you can specify the number of digits to be displayed in decimal places. For example, if the original data is "1.56" and the f
are used to tell the view engine how to Render HTML. In the preceding example,DataType.DateProperty to display the video date as a date, for example, the followingDataTypeThe attribute does not verify the data format:
[DataType(DataType.EmailAddress)] [DataType(DataType.PhoneNumber)] [DataType(DataType.Url)]
The properties listed above only provide the view engine to display data in the format of
Another useDataTypeAttribute method, you can explicitly setDataFormatString. The following code de
Formatting the output number in the gridview is often used. It seems that no one has written it. Record it here.
Use boundfield.The dataformatstring attribute is easy to implement. However, it must be used together with htmlencode = "false". Otherwise, dataformatstring does not work.
Example 1:
Example 2: Use a template
, and delete the key and name fields.
using System;using System.Collections.Generic;using System.ComponentModel.DataAnnotations;using System.ComponentModel.DataAnnotations.Schema;namespace ContosoUniversity.Models{ public class Instructor : Person { [DataType(DataType.Date)] [DisplayFormat(DataFormatString = {0:yyyy-MM-dd}, ApplyFormatInEditMode = true)] [Display(Name = Hire Date)] public DateTime HireDate { get; se
(+, errormessage = "Age cannot be large {2} cannot be less than {1} ")]38 public int: Age {get; set;} [ReadOnly (True)]41 [DisplayFormat (Applyformatineditmode = true, DataFormatString = "{0:c}")]42 [Required (errormessage = "Amount cannot be empty")]43 [Range (typeof (decimal), "20.0", "30.0", errormessage = "Amount between {1} and {2}")]44 Public decimal Money {get; set;} 45}46}In the model layer UserInfo class, we define the attri
")][DataType (Datatype.multilinetext)] //If you use a strong class type of auxiliary method @html.editorfor (model =>model) in the view, this field will be rendered as public string Content {get; set;}[Display (Name = "Author")][Stringlength (20)]public string AuthorName {get; set;}[Display (Name = "Publish Time")][DataType (Datatype.date)][DisplayFormat (dataformatstring= "{0:YYYY-MM-DD}")][DataType (Datatype.datetime)][DisplayFormat (
the form field[HttpPost]Public ActionResult createmenu (int id,string text,double price,string category)//the same name as the form field in form (name with the same name){......}Model Binder In addition to using multiple parameters in an action method, you can also use a type that matches the input field name:[HttpPost]Public ActionResult CreateMenu (Menu m){Viewbag.info = string. Format ("Menu created: {0}, Price: {1}, Category: {2}", M.text, M.price,M.category);Return View ("Index");}The mod
:u}", DT);//2005-11-05 14:23:23zLabel13.text = string. Format ("{0:u}", dt);//November 5, 2005 6:23:23Label14.text = string. Format ("{0:y}", dt);//November 2005Label15.text = string. Format ("{0}", dt);//2005-11-5 14:23:23? Label16.text = string. Format ("{0:yyyymmddhhmmssffff}", DT); Yyyymm can be set, such as Label16.text = string. Format ("{0:YYYYMMDD}", DT);Common binding date formatting: In addition, in the GridView DataFormatString formatted da
mentioning that the HyperLinkField connection that appears in the GridView template as the employee's name takes the pattern we defined in the URL template (employees/{name}/{id) above.formID= "Form1"runat= "Server"> DivID= "page"> Asp:gridviewID= "Gridviewemployees"runat= "Server"AutoGenerateColumns= "false"Width= "100%"> Columns> Asp:hyperlinkfieldHeaderText= "Name"DataTextField= "Name"DataNavigateUrlFields= "Name,id"datanavigateurlformatstring= "~/empl
tag, you can use the template editing interface. Here you can select the template you want to edit in the dropdown box and add any Web controls you like from the Toolbox.
In this tutorial, you first add a label to the ItemTemplate of the "Price and Inventory" template column. Then, on the label control's Smart label, tap Edit Data binding (edit DataBindings) and bind its Text property to the UnitPrice field.
Figure Five: Bind the label's Text property to the UnitPrice field
The unit price
asp.net|datagrid| Pagination | The sort DataGrid is an important control in asp.net, and often we make the DataGrid paginated and sortable, sometimes with the option to add. These are the methods that are often needed, but they are relatively simple.
Design ideas:
For convenience, we connect the Orders table of the Northwind database for SQL Server 2000 and get a data view of the table from the database. Use the SortCommand event in the DataGrid to implement sorting. Implement the selection wit
asp.net|datagrid| Pagination | sorting
The DataGrid is an important control in asp.net, and often we make the DataGrid paginated and sortable, sometimes with the option to be added. These are the methods that are often needed, but they are relatively simple.
Design ideas:
For convenience, we connect the Orders table of the Northwind database for SQL Server 2000 and get a data view of the table from the database. Use the SortCommand event in the DataGrid to implement sorting. Implement the sel
control in the edit column dialog box
It takes some time to modify the binding columns of the GridView control and remove the columns ProductID, SupplierID, CategoryID, QuantityPerUnit, UnitsInStock, UnitsOnOrder, and ReorderLevel. The operation is simple. You can remove these columns from the list in the lower left and click the delete button in red. Then, re-arrange, select the BIND columns CategoryName and SupplierName, and click the up arrow to release them before the UnitPrice column. Set
Movieinitializer class . Data. Entity, and the dropcreatedatabaseifmodelchanges parameter is modified to Moviedbcontext, which defaults to DbContext, otherwise you will be prompted not to rewrite the seed method , the parameters of seed are consistent with dropcreatedatabaseifmodelchanges, and when data is added or deleted, the function deletes the database and creates a new The eighth section describes the validity of the page validation input information, first of all in the client ver
(DataFormatString = "{0: C}")]Public double Price {get; set ;}[DataType (DataType. Date)]Public DateTime Date {get; set ;}[StringLength (10)]Public string Category {get; set ;}}
Verification features include: CompareAttribute used to compare different attributes, CreditCardAttribute used to verify the credit card number, EmailAddressAttribute used to verify the email address, used to compare the input and enumeration values
EnumDataTypeAttribute and
Dataformatstring= "{0: format string}"We know that {0} in DataFormatStringRepresents the data itself, and the format string after the colon represents the format that you want the data to appear in, and you can specify the number of digits that the decimal is to display after the specified format symbol. For example, the original data is"1.56", the output is "1.5" if the format is set to {0:N1}. Its commonly used numeric format is shown in the followi
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.