Robert,
Don't know 'what' exactly you want to display, but below is a sample of how you can display
data from an SQL Table in a "DataGrid" using ASP.NET (written in C#).
<!-------------------------------BEGIN EXAMPLE------------------------------------------>
<%@ Page Language="C#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!Page.IsPostBack) {
// Databind the data grid on the first request only
// (on postback, rebind only in paging and sorting commands)
BindGrid();
}
}
void DataGrid_Page(object sender, DataGridPageChangedEventArgs e) {
DataGrid1.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}
void DataGrid_Sort(object sender, DataGridSortCommandEventArgs e) {
DataGrid1.CurrentPageIndex = 0;
SortField = e.SortExpression;
BindGrid();
}
//---------------------------------------------------------
//
// Helpers
//
// use a property to keep track of the sort field, and
// save it in viewstate between postbacks
protected String SortField {
get {
object o = ViewState["SortField"];
return (o == null) ? String.Empty : (String)o;
}
set {
ViewState["SortField"] = value;
}
}
void BindGrid() {
// TODO: update the ConnectionString values for your application
string ConnectionString =
"server=ServerName;database=DatabaseName;UID=username;Password=password";
string CommandText;
// TODO: update the CommandText values for your application
if (SortField == String.Empty)
CommandText = "select Column1, Column2, Column3, Column4, Column5 from TableName
order by Column1";
else
CommandText = "select Column1, Column2, Column3, Column4, Column5 from TableName
order by " + SortField;
SqlConnection myConnection = new SqlConnection(ConnectionString);
SqlDataAdapter myCommand = new SqlDataAdapter(CommandText, myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds);
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
}
</script>
<html>
<head>
</head>
<body style="FONT-FAMILY: arial">
<h2>Database example of ASP.NET DataGrid w/Paging & Sorting
</h2>
<hr size="1" />
<form runat="server">
<asp:datagrid id="DataGrid1" runat="server" width="80%" CellSpacing="1" GridLines="None"
CellPadding="3" BackColor="White" ForeColor="Black" OnPageIndexChanged="DataGrid_Page"
PageSize="6" AllowPaging="true" OnSortCommand="DataGrid_Sort" AllowSorting="true">
<HeaderStyle font-bold="True" forecolor="white" backcolor="#4A3C8C"></HeaderStyle>
<PagerStyle horizontalalign="Right" backcolor="#C6C3C6"
mode="NumericPages"></PagerStyle>
<ItemStyle backcolor="#DEDFDE"></ItemStyle>
</asp:datagrid>
</form>
</body>
</html>
//--------------------------END EXAMPLE HERE------------------------------------------------>
NOTE: Copy the code into notepad, then save the file with a ".aspx" extension. The example is
VERY basic, but should give you a beginning point!
HTH
JPM