后台:
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds;
OleDbDataAdapter dr;
DataColumn wenzhangtype;
//Grab the Categories and Products table
ds = new DataSet();
string strDBPath = System.Configuration.ConfigurationSettings.AppSettings["DBPath"];
string strConn = System.Configuration.ConfigurationSettings.AppSettings["Connection"] + Server.MapPath(strDBPath);
OleDbConnection myConnection = new OleDbConnection(strConn);
dr = new OleDbDataAdapter("Select * From ArticleType", myConnection);
myConnection.Open();
dr.Fill(ds, "ArticleType");
dr.SelectCommand = new OleDbCommand("Select * From Article", myConnection);
dr.Fill(ds, "Article");
myConnection.Close();
//Add Parent/Child Relationship
ds.Relations.Add("catprods", ds.Tables["ArticleType"].Columns["typeid"], ds.Tables["Article"].Columns["typeid"]);
//Add the aggregate column
wenzhangtype = new DataColumn(("文章数"), System.Type.GetType("System.Decimal"));
wenzhangtype.Expression = "Count( Child.NewsID )";
ds.Tables["ArticleType"].Columns.Add(wenzhangtype);
//Bind to the DataGrid
DataGrid1.DataSource = ds;
DataGrid1.DataMember = "ArticleType";
DataGrid1.DataBind();
}
前台:
<asp:DataGrid
ID="DataGrid1"
Runat="Server" />