ButtonField.DataTextFormatString Özellik

Tanım

Alanın değeri için görüntüleme biçimini belirten dizeyi alır veya ayarlar.

public:
 virtual property System::String ^ DataTextFormatString { System::String ^ get(); void set(System::String ^ value); };
public virtual string DataTextFormatString { get; set; }
member this.DataTextFormatString : string with get, set
Public Overridable Property DataTextFormatString As String

Özellik Değeri

String

Alanın değeri için görüntüleme biçimini belirten bir biçim dizesi. Varsayılan, alan değerine özel biçimlendirme uygulanmadığını gösteren boş bir dizedir ("").

Örnekler

Aşağıdaki kod örneği, bir alanın değerleri için özel bir görüntüleme biçimi belirtmek üzere özelliğinin nasıl kullanılacağını DataTextFormatString gösterir.


<%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void AuthorsGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
  {
  
    // If multiple ButtonField column fields are used, use the
    // CommandName property to determine which button was clicked.
    if(e.CommandName=="Select")
    {
    
      // Convert the row index stored in the CommandArgument
      // property to an Integer.
      int index = Convert.ToInt32(e.CommandArgument);    
    
      // Get the last name of the selected author from the appropriate
      // cell in the GridView control.
      GridViewRow selectedRow = AuthorsGridView.Rows[index];
      TableCell lastNameCell = selectedRow.Cells[1];
      string lastName = lastNameCell.Text;  
    
      // Display the selected author.
      Message.Text = "You selected " + lastName + ".";
      
    }
    
  }
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ButtonField DataTextField Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>ButtonField DataTextField Example</h3>
      
      <asp:label id="Message"
        forecolor="Red"
        runat="server"
        AssociatedControlID="AuthorsGridView"/>
                    
      <!-- Set the DataTextField property of the ButtonField -->
      <!-- declaratively. Set the DataTextFormatString       -->
      <!-- property to apply special formatting to the text. -->
      <asp:gridview id="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource" 
        autogeneratecolumns="false"
        onrowcommand="AuthorsGridView_RowCommand" 
        runat="server">
                
        <columns>
                
          <asp:buttonfield buttontype="Link" 
            commandname="Select"
            headertext="Select Author"
            datatextfield="au_lname"
            datatextformatstring="[{0}]"    
            text="Select"/>
          <asp:boundfield datafield="au_fname" 
            headertext="First Name"/>
                
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_lname], [au_fname] FROM [authors]"
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

<%@ Page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Sub AuthorsGridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
  
    ' If multiple ButtonField column fields are used, use the
    ' CommandName property to determine which button was clicked.
    If e.CommandName = "Select" Then
    
      ' Convert the row index stored in the CommandArgument
      ' property to an Integer.
      Dim index As Integer = Convert.ToInt32(e.CommandArgument)
    
      ' Get the last name of the selected author from the appropriate
      ' cell in the GridView control.
      Dim selectedRow As GridViewRow = AuthorsGridView.Rows(index)
      Dim lastNameCell As TableCell = selectedRow.Cells(1)
      Dim lastName As String = lastNameCell.Text
    
      ' Display the selected author.
      Message.Text = "You selected " & lastName & "."
      
    End If
    
  End Sub
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ButtonField DataTextField Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>ButtonField DataTextField Example</h3>
      
      <asp:label id="Message"
        forecolor="Red"
        runat="server"
        AssociatedControlID="AuthorsGridView"/>
                    
      <!-- Set the DataTextField property of the ButtonField -->
      <!-- declaratively. Set the DataTextFormatString       -->
      <!-- property to apply special formatting to the text. -->
      <asp:gridview id="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource" 
        autogeneratecolumns="false"
        onrowcommand="AuthorsGridView_RowCommand"
        runat="server">
                
        <columns>
                
          <asp:buttonfield buttontype="Link" 
            commandname="Select"
            headertext="Select Author"
            datatextfield="au_lname"
            datatextformatstring="[{0}]"    
            text="Select"/>
          <asp:boundfield datafield="au_fname" 
            headertext="First Name"/>
                
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_lname], [au_fname] FROM [authors]"
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

Açıklamalar

nesnesinde DataTextFormatString ButtonField görüntülenen değerler için özel bir görüntüleme biçimi belirtmek için özelliğini kullanın. DataTextFormatString Özellik ayarlanmamışsa, alanın değeri herhangi bir özel biçimlendirme olmadan görüntülenir.

Not

Biçim dizesi yalnızca DataTextField özellik ayarlandığında uygulanır.

Biçim dizesi herhangi bir değişmez değer dizesi olabilir ve genellikle alanın değeri için bir yer tutucu içerir. Örneğin, biçim dizesinde "Item Value: {0}"``{0} yer tutucu, nesnede ButtonField görüntülendiğinde alanın değeriyle değiştirilir. Biçim dizesinin geri kalanı değişmez metin olarak görüntülenir.

Not

Biçim dizesi yer tutucu içermiyorsa, veri kaynağındaki alanın değeri son görüntüleme metnine dahil değildir.

Yer tutucu, iki nokta üst üste ile ayrılmış ve { A : Bxx } biçiminde küme ayraçları içinde sarmalanmış iki bölümden oluşur. İki nokta üst üste işaretinden önceki değer (A genel örnekte), sıfır tabanlı parametre listesinde alan değerinin dizinini belirtir.

Not

Bu A parametre biçimlendirme söz diziminin bir parçasıdır. Her hücrede yalnızca bir alan değeri olduğundan, bu değer yalnızca 0 olarak ayarlanabilir.

İki nokta üst üste ve iki nokta üst üsteden sonraki değerler isteğe bağlıdır. İki nokta üst üste işaretinden sonraki karakter (B genel örnekte) değerin görüntüleneceği biçimi belirtir. Aşağıdaki tabloda ortak biçimler listelenmektedir.

Karakter biçimlendirme Description
C Sayısal değerleri para birimi biçiminde görüntüler.
D Sayısal değerleri ondalık biçimde görüntüler.
E Sayısal değerleri bilimsel (üstel) biçimde görüntüler.
F Sayısal değerleri sabit biçimde görüntüler.
G Sayısal değerleri genel biçimde görüntüler.
N Sayısal değerleri sayı biçiminde görüntüler.
X Sayısal değerleri onaltılık biçimde görüntüler.

Not

Xdışında, biçim karakterleri büyük/küçük harfe duyarlı değildir. Biçim X karakteri, belirtilen durumda onaltılık karakterleri görüntüler.

Biçim karakterinden sonraki değer (xx genel örnekte) görüntülenecek anlamlı basamak veya ondalık basamak sayısını belirtir. Örneğin, biçim dizesi "{0:F2}" iki ondalık basamaklı sabit noktalı bir sayı görüntüler.

Dizeleri biçimlendirme hakkında daha fazla bilgi için bkz . Biçimlendirme Türleri.

Bu özelliğin değeri görünüm durumunda depolanır.

Şunlara uygulanır

Ayrıca bkz.