BaseDataBoundControl.DataSource プロパティ
アセンブリ: 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>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からBaseDataBoundControl.DataSource プロパティを検索する場合は、下記のリンクをクリックしてください。

- BaseDataBoundControl.DataSource プロパティのページへのリンク