开发者

Dynamic data population like stackoverflow comments?

I'm trying to create a comment system just like SO has, but first, I'd like to show first 5 comments for a post and show rest if "display all comments" is clicked for the desired reply.

What is the best way of doing this? I really couldn't found a good way for doing what I want. I must be missing something.

For info, comments datasource is a nested repeater in my page. The outer repeater is replies and inner repeater is comments. Currently I'm binding all comments for all results (even if it has 10000 replies.). Also, I don't want to do paging for comments. I just want it to work the same way as SO.

Any ide开发者_C百科as?

EDIT: Now I'm thinking of having 2 tables for comments which are:

  • A table which only has 5 rows of data and will be visible by default. I need filtering to do this. Linq filtering code would be great!

  • A table which has all the results. No filtering. I have no problems with this one.

So here is what I have for the data:

DataRowView dv = e.Item.DataItem as DataRowView;
        if (dv != null)
        {
            Repeater commentRepeater = e.Item.FindControl("childRepeater") as Repeater;
            if (commentRepeater != null)
            {
                commentRepeater.DataSource = dv.CreateChildView("myrelation");
                commentRepeater.DataBind();
            }
        }

As you can see, I have created a relation between tables in my dataset and I'm binding that datarow to my repeater. I need to do top 5 filtering on the datarow.

Thank you


I suggest to use JSON returned from ASP.NET Web Services with jQuery.

http://www.mikesdotnetting.com/Article/96/Handling-JSON-Arrays-returned-from-ASP.NET-Web-Services-with-jQuery

http://www.electrictoolbox.com/json-data-jquery-php-mysql/


If you want to append the left over items to the current repeater item you could have a button at the end of the coments that is attached to a jquery function that will fetch the rest of the comments for you. Then once the data is recieved your function would just append the comments to the list of other comments mimicing what the repeater was doing and replacing the 'show all' button.

If you don't want to use any ajax to do this then you will probably need to rebind the comments Repeater with a new set of data that is not limited to just the first 5 results.

EDIT: Based on your comment and changes you have editted, I would go with one table with all comments and in the DataBinding of each comment set the row style to visible with a global counter. Once your have more than 5 set the style to a hidden style for each item. When they click the show all button, just switch the style from hidden to visible for the rest comments that are hidden. This will save you duplicating the data for the first 5 items which could turn into a lot of extra rows if there are a lot of answers with comments.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜