Aracılığıyla paylaş


GridView Oluşturucu

Tanım

GridView sınıfının yeni bir örneğini başlatır.

public:
 GridView();
public GridView ();
Public Sub New ()

Örnekler

Aşağıdaki örnekte, bir sayfaya dinamik olarak denetim eklemek GridView için oluşturucunun nasıl kullanılacağı gösterilmektedir.


<%@ 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 Page_Load(Object sender, EventArgs e)
    {
        
        // Create a new GridView object.
        GridView customersGridView = new GridView();
         
        // Set the GridView object's properties.
        customersGridView.ID = "CustomersGridView";
        customersGridView.DataSourceID = "CustomersSource";
        customersGridView.AutoGenerateColumns = true;
        
        // Add the GridView object to the Controls collection
        // of the PlaceHolder control.
        GridViewPlaceHolder.Controls.Add(customersGridView);
        
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>GridView Constructor Example</h3>

      <asp:placeholder id="GridViewPlaceHolder"
        runat="Server"/>

      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="CustomersSource"
        selectcommand="Select [CustomerID], [CompanyName], [City] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>

    </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 Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        
    ' Create a new GridView object.
    Dim customersGridView As New GridView()
         
    ' Set the GridView object's properties.
    customersGridView.ID = "CustomersGridView"
    customersGridView.DataSourceID = "CustomersSource"
    customersGridView.AutoGenerateColumns = True
        
    ' Add the GridView object to the Controls collection
    ' of the PlaceHolder control.
    GridViewPlaceHolder.Controls.Add(customersGridView)
        
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>GridView Constructor Example</h3>

      <asp:placeholder id="GridViewPlaceHolder"
        runat="Server"/>

      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="CustomersSource"
        selectcommand="Select [CustomerID], [CompanyName], [City] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>

    </form>
  </body>
</html>

Açıklamalar

Sınıfının yeni bir örneğini başlatmak için bu oluşturucuyu GridView kullanın. Bir sayfaya dinamik olarak denetim eklemek GridView için yeni GridView bir nesne oluşturun, özelliklerini ayarlayın ve sonra bunu gibi PlaceHolderbir kapsayıcı denetimi koleksiyonuna Control.Controls ekleyin.

Şunlara uygulanır

Ayrıca bkz.