BaseDataBoundControl.DataSource プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > BaseDataBoundControl.DataSource プロパティの意味・解説 

BaseDataBoundControl.DataSource プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

データ バインド コントロールデータ項目一覧取得する際の取得元となるオブジェクト取得または設定します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

<BindableAttribute(True)> _
<ThemeableAttribute(False)> _
Public Overridable Property
 DataSource As Object
Dim instance As BaseDataBoundControl
Dim value As Object

value = instance.DataSource

instance.DataSource = value
[BindableAttribute(true)] 
[ThemeableAttribute(false)] 
public virtual Object DataSource { get; set;
 }
[BindableAttribute(true)] 
[ThemeableAttribute(false)] 
public:
virtual property Object^ DataSource {
    Object^ get ();
    void set (Object^ value);
}
/** @property */
public Object get_DataSource ()

/** @property */
public void set_DataSource (Object value)

プロパティ
データ バインド コントロールデータ取得元となるデータ ソースを表すオブジェクト既定値null 参照 (Visual Basic では Nothing) です。

解説解説

DataSource プロパティ設定すると、ValidateDataSource メソッド呼び出されます。さらに、データ バインド コントロールが既に初期化されている場合、OnDataPropertyChanged メソッド呼び出されて、RequiresDataBinding プロパティtrue設定されます。

このプロパティは、テーマまたはスタイル シート テーマによって設定することはできません。詳細については、ThemeableAttribute、ASP.NETテーマスキン概要 の各トピック参照してください

使用例使用例

データ バインド コントロールDataSource プロパティ使用方法を、次のコード例示します。この例では、GridView コントロールDataSet オブジェクトバインドされますDataSource プロパティ設定した後、 DataBind メソッド明示的に呼び出します。

<%@ Page language="VB" %>
<%@ import namespace="System.Data"
 %>
<%@ import namespace="System.Data.SqlClient"
 %>

<script runat="server">

  Sub Page_Load(ByVal sender As
 Object, ByVal e As EventArgs)
    
    ' This example uses Microsoft SQL Server and connects
    ' to the Northwind sample database. The data source needs
    ' to be bound to the GridView control only when the 
    ' page is first loaded. Thereafter, the values are
    ' stored in view state.                      
    If Not IsPostBack Then
        
      ' Declare the query string.
      Dim queryString As String
 = _
        "Select [CustomerID], [CompanyName], [Address], [City],
 [PostalCode], [Country] From [Customers]"
        
      ' Run the query and bind the resulting DataSet
      ' to the GridView control.
      Dim ds As DataSet = GetData(queryString)
      If (ds.Tables.Count > 0) Then
      
        AuthorsGridView.DataSource = ds
        AuthorsGridView.DataBind()
      
      Else
      
        Message.Text = "Unable to connect to the database."
        
      End If
            
    End If
    
  End Sub
    
  Function GetData(ByVal queryString As
 String) As DataSet
    
    ' Retrieve the connection string stored in the Web.config file.
    Dim connectionString As String
 = ConfigurationManager.ConnectionStrings("NorthWindConnectionString").ConnectionString
 
    Dim ds As New DataSet()
        
    Try

      ' Connect to the database and run the query.
      Dim connection As New
 SqlConnection(connectionString)
      Dim adapter As New
 SqlDataAdapter(queryString, Connection)
        
      ' Fill the DataSet.
      Adapter.Fill(ds)
            
    
    Catch ex As Exception
        
      ' The connection failed. Display an error message.
      Message.Text = "Unable to connect to the database."
        
    End Try
        
    Return ds
        
  End Function
    
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridView DataBind Example</h3>
            
      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>
               
      <br/>    

      <asp:gridview id="AuthorsGridView" 
        autogeneratecolumns="true" 
        runat="server">
      </asp:gridview>
                        
    </form>
  </body>
</html>

<%@ Page language="C#" %>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.SqlClient" %>

<script runat="server">

  void Page_Load(Object sender, EventArgs e)
  {
    
    // This example uses Microsoft SQL Server and connects
    // to the Northwind sample database. The data source needs
    // to be bound to the GridView control only when the 
    // page is first loaded. Thereafter, the values are
    // stored in view state.                      
    if(!IsPostBack)
    {
        
      // Declare the query string.
      String queryString = 
        "Select [CustomerID], [CompanyName], [Address], [City], [PostalCode],
 [Country] From [Customers]";
        
      // Run the query and bind the resulting DataSet
      // to the GridView control.
      DataSet ds = GetData(queryString);
      if (ds.Tables.Count > 0)
      {
        AuthorsGridView.DataSource = ds;
        AuthorsGridView.DataBind();
      }
      else
      {
        Message.Text = "Unable to connect to the database.";
      }
            
    }     
    
  }
    
  DataSet GetData(String queryString)
  {

    // Retrieve the connection string stored in the Web.config file.
    String connectionString = ConfigurationManager.ConnectionStrings["NorthWindConnectionString"].ConnectionString;
      
 
    DataSet ds = new DataSet();
        
    try
    {
      // Connect to the database and run the query.
      SqlConnection connection = new SqlConnection(connectionString);
        
      SqlDataAdapter adapter = new SqlDataAdapter(queryString,
 connection);
        
      // Fill the DataSet.
      adapter.Fill(ds);
            
    }
    catch(Exception ex)
    {
        
      // The connection failed. Display an error message.
      Message.Text = "Unable to connect to the database.";
        
    }
        
    return ds;
        
  }
    
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridView DataBind Example</h3>
            
      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>
               
      <br/>    

      <asp:gridview id="AuthorsGridView" 
        autogeneratecolumns="true" 
        runat="server">
      </asp:gridview>
                        
    </form>
  </body>
</html>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
BaseDataBoundControl クラス
BaseDataBoundControl メンバ
System.Web.UI.WebControls 名前空間
DataSourceID


このページでは「.NET Framework クラス ライブラリ リファレンス」からBaseDataBoundControl.DataSource プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からBaseDataBoundControl.DataSource プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からBaseDataBoundControl.DataSource プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「BaseDataBoundControl.DataSource プロパティ」の関連用語

BaseDataBoundControl.DataSource プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



BaseDataBoundControl.DataSource プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS