Posted By: Winston Pang | Apr 16th, 2007 @ 3:47 PM
page 1 of 1
Comments: 3 | Views: 3447

So i'm making my own Blog, and it's going to be simple the general layout is:


DATE - POST TITLE
- - - - - - - - - - - - - - - - -
POST CONTENTS
- - - - - - - - - - - - - - - - -
TAGS | COMMENT LINK(NUMBER OF COMMENTS)


So i've used a GridView, and supplied an SqlDataSource all works well, but now i'm trying to incorporate the TAGS feature, but it's kind of hard to do it all in the one single query, i don't think it's even possible.


My current schema goes something like this


Post - PostID_PK, Post title, etc
Comment - CommentID_PK, CommentContents, PostID_FK
Tag - TagID_PK, TagName
Tag_Post - Tag_Post_ID_PK, TagID_FK, PostID_FK

So that's the general layout, for my SqlDataSource i've got a query that will fetch all Posts, and also fetch the number of comments for each post, just a count. Works all well. But now i need to fetch all the Post_Tag records for EACH post, the results will be strange and i'm not sure how it'll work out in DataBinding.

My next step is to make my own custom data source objects, but i'm not exactly sure how i should model my custom data source objects for me to make my <%# Eval("FieldName") %> calls work still inside my aspx page.

Thank you in advance.


Winston

odujosh
odujosh
Need Microsoft SUX now!
ObjectDataSource.

Make  Class that does multiple queries or calls a Data Access Layer that does. Bind an instance of class to your gridview via a Object DataSource.
odujosh
odujosh
Need Microsoft SUX now!
ObjectDataSource uses generics with collections. You make a class that represents the idea of data you input into it like:


public class Person
{

/*use properties if you care about that sort of thing I omit them for
conciseness */

public string FirstName;
public string LastName;
public DateTime BirthDate;
public List<Person> Babies;
}

Then you can bind using standard <%# %> statements using Eval and standard C# calls.

You Data Access Layer would then just bind data to List<Persons> or any collection that implemenets IEnumerable<T>
page 1 of 1
Comments: 3 | Views: 3447
Microsoft Communities