APNSoft.com - Web Controls, components for ASP.NET
 About Us 

Controls Suite 4.5

Reference Book
Component Parts
Binding to Data
Appearance Customization
Edit Form
Client-side API
Server-side API
Live Demos

APNSoft DataGrid displays data obtained from a database or other data source. The data is presented in tabular format. To bind to a data source, set the DataSource property and call the DataBind() method. DataGrid supports different data sources: DataView, DataTable, DataSet, DataReader and any object that implements IEnumerable interface.

protected void Page_Load(object sender, EventArgs e)
    //Define SQL query
    string SqlQuery = @"SELECT CustomerID, CompanyName, ContactName FROM Customers";

    //Get DataTable
    DataTable myDataSource = GetDataTable(SqlQuery);

    //Set the data source
    myDataGrid.KeyFieldName = "CustomerID";
    myDataGrid.DataSource = myDataSource;

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    'Define SQL query
    Dim SqlQuery As String = "SELECT CustomerID, CompanyName, ContactName FROM Customers"

    'Get DataTable (MS Access Database)
    Dim myDataSource As DataTable = GetDataTable(SqlQuery)

    'Set the data source
    myDataGrid.KeyFieldName = "CustomerID"
    myDataGrid.DataSource = myDataSource

End Sub

Also, APNSoft DataGrid has the DataSourceID property. This property can be used to refer to actual .NET data source object (SqlDataSource) from which the DataGrid retrieves its list of data items.

<asp:SqlDataSource id="mySqlDataSource" runat="server" 
    SelectCommand="..." />

<APNSoft:APNSoftDataGrid id="myDataGrid" runat="server" 
    DataSourceID="mySqlDataSource" />

© 2003-2024 APNSoft. All rights reserved.    Terms of use.