Datasheet
Listing 1-10 (continued)
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID=”ArticlesODS” runat=”server”
SelectMethod=”GetArticles” TypeName=”Articles”>
<SelectParameters>
<asp:QueryStringParameter DefaultValue=”2006”
Name=”year” QueryStringField=”year”
Type=”String” />
<asp:QueryStringParameter DefaultValue=”01”
Name=”month” QueryStringField=”month”
Type=”String” />
</SelectParameters>
</asp:ObjectDataSource>
</form>
</body>
</html>
Being an advocate of well-designed n-tier architectures, I decided to implement article management
with business objects and a formal data access layer. This is why you see the ObjectDataSource control in
the
MonthView.aspx page. It was handy to map query string parameters directly to the GetArticles
method of the Articles class, as shown in Listing 1-11.
Listing 1-11: The Articles class contains a list of article objects: articles.cs
using System;
using System.Collections.Generic;
/// <summary>
/// List of Articles
/// </summary>
public class Articles : List<Article>
{
public List<Article> GetArticles(string year, string month)
{
ArticleData dal = new ArticleData();
dal.GetArticles(this, year, month);
return this;
}
}
The Articles class in Listing 1-11 takes advantage of the new generics feature of the C# programming
language to create a strongly typed collection of
Article objects. By inheriting List<Article> we get the
benefits of generics with the capability to name our type something a bit more understandable. Listing
1-12 shows the data access layer, represented by the ArticleData class.
Listing 1-12: The ArticleData class populates the current list with new articles from
the data source: ArticleData.cs
using System;
using System.Collections;
using System.Collections.Generic;
20
Chapter 1
04_597663 ch01.qxp 4/25/06 9:54 PM Page 20