1. A. Run
1. B. Source Code (main code summary)
/App_Code/DBConnection. cs
/App_Code/CategoryInfo. cs
Copy codeThe Code is as follows: using System. Collections. Generic;
Public class CategoryInfo
{
Int categoryid;
String categoryname;
String categorydesc;
IList <ArticleInfo> articles;
/// <Summary>
/// 1. subnested data
/// </Summary>
Public IList <ArticleInfo> Articles
{
Get {return articles ;}
Set {articles = value ;}
}
Public int Categoryid
{
Get {return categoryid ;}
Set {categoryid = value ;}
}
Public string Categoryname
{
Get {return categoryname ;}
Set {categoryname = value ;}
}
Public string Categorydesc
{
Get {return categorydesc ;}
Set {categorydesc = value ;}
}
Public CategoryInfo ()
{
}
Public CategoryInfo (int categoryid, string categoryname, string categorydesc, IList <ArticleInfo> articles)
{
This. categoryid = categoryid;
This. categoryname = categoryname;
This. categorydesc = categorydesc;
This. articles = articles;
}
}
/App_Code/ArticleInfo. cs
/App_Code/categorycategory. csCopy codeThe Code is as follows: using System. Data;
Using System. Data. SqlClient;
Using System. Collections. Generic;
Public class categorycategory
{
Public static IList <CategoryInfo> SelectAll ()
{
IList <CategoryInfo> allcate = new List <CategoryInfo> ();
String SQL = "select category. categoryid, categoryname, categorydesc, id, title, author from category inner join article on category. categoryid = article. categoryid order by category. categoryid ";
SqlConnection con = new DBConnection (). Con;
SqlCommand com = new SqlCommand ();
Com. Connection = con;
Com. CommandText = SQL;
Com. CommandType = CommandType. Text;
Con. Open ();
SqlDataReader sdr = com. ExecuteReader ();
Int tempcategoryid = 0;
CategoryInfo cate = null;
While (sdr. Read ())
{
Int categoryid = sdr. GetInt32 (0 );
// If the category changes, a new cate object is created.
If (categoryid! = Tempcategoryid)
{
Cate = new CategoryInfo (sdr. GetInt32 (0), sdr. GetString (1), sdr. GetString (2), new List <ArticleInfo> ());
Allcate. Add (cate );
Tempcategoryid = categoryid; // pay the new category ID to the ID
}
ArticleInfo art = new ArticleInfo (sdr. GetInt32 (3), sdr. GetString (4), sdr. GetString (5 ));
Cate. Articles. Add (art );
}
Con. Close ();
Return allcate;
}
Public categorycategory ()
{
//
// TODO: add the constructor logic here
//
}
}
/App_Code/articleworkflow. cs
, 6
/Default. aspxCopy codeThe Code is as follows: <% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. aspx. cs" Inherits = "_ Default" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div style = "text-align: center">
<Asp: Repeater ID = "RepCate" runat = "server">
<HeaderTemplate>
<Table border = "1">
<Tr>
<Td> category id </td>
<Td> category name </td>
<Td> Category Description </td>
</Tr>
</HeaderTemplate>
<ItemTemplate>
<Tr>
<Td> <% # Eval ("categoryid") %> </td>
<Td> <% # Eval ("categoryname") %> </td>
<Td> <% # Eval ("categorydesc") %> </td>
</Tr>
<Tr>
<Td> News of this Category </td>
<Td colspan = "2">
<Asp: Repeater ID = "RepArticle" runat = "server" DataSource = '<% # Eval ("articles") %>'>
<HeaderTemplate>
<Table border = "1" style = "background-color: #00FF00;">
<Tr>
<Td> News No. </td>
<Td> News Title </td>
<Td> News author </td>
</Tr>
</HeaderTemplate>
<ItemTemplate>
<Tr>
<Td> <% # Eval ("id") %> </td>
<Td>
<Asp: HyperLink ID = "Hl1" runat = "server" Text = '<% # Eval ("title") %> 'navigateurl =' <% # string. format ("ShowArticle. aspx? Id = {0} ", Eval (" id ") %> '> </asp: HyperLink>
</Td>
<Td> <% # Eval ("author") %> </td>
</Tr>
</ItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
</Asp: Repeater>
</Td>
</Tr>
</ItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
</Asp: Repeater>
</Div>
</Form>
</Body>
</Html>
/Default. aspx. csCopy codeThe Code is as follows: using System;
Public partial class _ Default: System. Web. UI. Page
{
Private void BindCategory ()
{
RepCate. DataSource = categorylistener. SelectAll ();
RepCate. DataBind ();
}
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
BindCategory ();
}
}
}
/Web. config
1. C. Download Resources