View Single Post
  #1 (permalink)  
Old February 8th, 2009, 06:20 PM
philthy philthy is offline
Authorized User
Join Date: Mar 2007
Location: , , Denmark.
Posts: 52
Thanks: 6
Thanked 2 Times in 2 Posts
Default Passing articleID to ObjectDataSource..

I’m working on tags for my articles. Everything is pretty much working now. I can create tags, and when I create a new article, I have the available tags listed in a checkbox list, so I can check the ones I want associated with my article. When I hit save, everything is saved correctly in the database.

Now, I want to show the tags for each article in the articles listing, and this is where I’m a little stuck. I have built my article list with a ListView. I have made a class Tag, which has a GetTagsByArticle method. So, I put an ObjectDataSource control on the page and set my Tag class as type for it. Then In my ListView, I tried to put a BulletedList control and hook it up to my ObjectDataSource. When I run the page, I get no output.

To test it, I tried to set a default value for the asp:Parameter to an articleID that exists in the database, and this works, it writes out all the tags for that particular article. Of course, this is not how it should be, it should write out the tags for each article, so I need to get the articleID for the current article in each loop of the ListView.

So far, I have been using Eval to get the values from the ObjectDataSource. I feel like this should be as easy as hooking the Datacontrol up to the ObjectDataSource, but I can’t figure it out. Maybe I have been staring myself blind on it…
Any ideas?

This is the code for the ObjectDataSource.

<asp:ObjectDataSource ID="ObjTags" runat="server" SelectMethod="GetTagsByArticle"
TypeName="SG.Blog.BLL.Articles.Tag" OldValuesParameterFormatString="original_{0}">
<asp:Parameter Name="articleID" Type="Int32"/>