·您的位置: 首页 » 资源教程 » 编程开发 » ASP.NET » 按以下步骤

按以下步骤

类别: ASP.NET教程  评论数:0 总得分:0
1.打开开始菜单
2.选择程序中的Microsoft .NET FrameWork
3.选择Documention
4.选择Index选项卡
5.输入“DataFormatString property”
6.双出出现的第一个关键词。
7.以下出现内容:
   .NET Framework Class Library   

BoundColumn.DataFormatString PropertySee Also
BoundColumn Class | BoundColumn Members | System.Web.UI.WebControls Namespace | String.Empty | DataGrid | Formatting Overview
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP
Language
C#

C++

JScript

Visual Basic

Show All

This is preliminary documentation and subject to change.
Send feedback on this topic.


Gets or sets the string that specifies the display format for items in the column.

[Visual Basic]
Overridable Public Property DataFormatString As String
[C#]
public virtual string DataFormatString {get; set;}
[C++]
public: __property virtual String* get_DataFormatString();
public: __property virtual void set_DataFormatString(String*);
[JScript]
public   function get DataFormatString() : String;
public function set DataFormatString(String);
Property Value
A formatting string that specifies the display format of items in the column. The default value is String.Empty.

Remarks
Use the DataFormatString property to provide a custom format for the items in the column.

The data format string consists of two parts, separated by a colon, in the form {A:Bxx}. For example, the formatting string, {0:D2}, would format the cell to display a number with two decimal places.

Note   The entire string must be enclosed in curly braces to denote that it is a format string and not a literal string. Any text outside the curly braces is displayed as literal text.
The value before the colon ( A in the general example) specifies the parameter index in a zero-based list of parameters.

Note   This value can only be set to 0 because there is only one value in each cell.
The character after the colon ( B in the general example) specifies the format to display the value in. The following table lists the common formats.

Format Character Description
C  Displays numeric values in currency format.
D  Displays numeric values in decimal format.
E  Displays numeric values in scientific (exponential) format.
F  Displays numeric values in fixed format.
G  Displays numeric values in general format.
N  Displays numeric values in number format.
X  Displays numeric values in hexadecimal format.

Note   The format character is not case-sensitive, except for X, which displays the hexadecimal characters in the case specified.
The value after the format character ( xx in the general example) specifies the number of significant digits or decimal places to display the value in.

For more information on formatting strings, see Formatting Overview.

Example
[Visual Basic, C#] The following example demonstrates how to use the DataFormatString property to specify currency format for the column that displays the prices in of the DataGrid control.

[C#]
<%@ Import Namespace="System.Data" %>

<html>
   <script language="C#" runat ="server">

      ICollection CreateDataSource()
      {
         DataTable dt = new DataTable();
         DataRow dr;

         dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
         dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
         dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));

         for (int i = 0; i < 9; i++)
         {
            dr = dt.NewRow();

            dr[0] = i;
            dr[1] = "Item " + i.ToString();
            dr[2] = 1.23 * (i + 1);

            dt.Rows.Add(dr);
         }

         DataView dv = new DataView(dt);
         return dv;
      }

      void Page_Load(Object sender, EventArgs e)
      {

         if (!IsPostBack)
         {
            // need to load this data only once
            ItemsGrid.DataSource= CreateDataSource();
            ItemsGrid.DataBind();
         }
      }

   </script>

<body>

   <form runat =server>

      <h3><font face="Verdana">BoundColumn Example</font></h3>

      <b>Product List</b>

      <asp:DataGrid id="ItemsGrid"
           BorderColor="black"
           BorderWidth="1"
           CellPadding="3"
           AutoGenerateColumns="false"
           runat ="server">

         <HeaderStyle BackColor="#00aaaa">
         </HeaderStyle>

         <Columns>

            <asp:BoundColumn
                 HeaderText="Number"
                 DataField="IntegerValue">
            </asp:BoundColumn>

            <asp:BoundColumn
                 HeaderText="Description"
                 DataField="StringValue">
            </asp:BoundColumn>

            <asp:BoundColumn
                 HeaderText="Price"
                 DataField="CurrencyValue"
                 DataFormatString="{0:c}">
            </asp:BoundColumn>

         </Columns>

      </asp:DataGrid>

   </form>

</body>
</html>
[Visual Basic]
<%@ Import Namespace="System.Data" %>

<html>
   <script language="VB" runat ="server">
   Function CreateDataSource() As ICollection
       Dim dt As New DataTable()
       Dim dr As DataRow
       
       dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
       dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
       dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
       
       Dim i As Integer
       For i = 0 To 8
           dr = dt.NewRow()
           
           dr(0) = i
           dr(1) = "Item " + i.ToString()
           dr(2) = 1.23 *(i + 1)
           
           dt.Rows.Add(dr)
       Next i
       
       Dim dv As New DataView(dt)
       Return dv
   End Function \'CreateDataSource


   Sub Page_Load(sender As Object, e As EventArgs)
       
       If Not IsPostBack Then
           \' need to load this data only once
           ItemsGrid.DataSource = CreateDataSource()
           ItemsGrid.DataBind()
       End If
   End Sub \'Page_Load
   </script>
<body>

   <form runat =server>

      <h3><font face="Verdana">BoundColumn Example</font></h3>

      <b>Product List</b>

      <asp:DataGrid id="ItemsGrid"
           BorderColor="black"
           BorderWidth="1"
           CellPadding="3"
           AutoGenerateColumns="false"
           runat ="server">

         <HeaderStyle BackColor="#00aaaa">
         </HeaderStyle>

         <Columns>

            <asp:BoundColumn
                 HeaderText="Number"
                 DataField="IntegerValue">
            </asp:BoundColumn>

            <asp:BoundColumn
                 HeaderText="Description"
                 DataField="StringValue">
            </asp:BoundColumn>

            <asp:BoundColumn
                 HeaderText="Price"
                 DataField="CurrencyValue"
                 DataFormatString="{0:c}">
            </asp:BoundColumn>

         </Columns>

      </asp:DataGrid>

   </form>

</body>
</html>
[C++, JScript] No example is available in C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button  in the upper-left corner of the page.

Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP

See Also
BoundColumn Class | BoundColumn Members | System.Web.UI.WebControls Namespace | String.Empty | DataGrid | Formatting Overview



-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:

纯粹空间 softpure.com
Copyright © 2006-2012 暖阳制作 版权所有
承接程序设计 网页设计
QQ: 15242663 (隐身在线 拒绝闲聊)  Email: faisun@sina.com

 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛  

百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1