Reputation: 3905
I have webpage that has details view. I want to add comment box where user can see/add/edit/save comments. Once saved, the comments will be stored into db with record being displayed (storyID). I have table with columns StoryID and Comments where I would like to store comments.
Details view shows article based on session variable (storyid)
Is there any code sample that I can use? Spent good one hour but not luck.
Many thanks in advance
Upvotes: 0
Views: 718
Reputation: 6532
I've done similar things, here are a few ideas to think about.
Get a better DB layout, with your current 2 columns how will it order the thread correctly?
Column Idea ( CommentId, StoryId, Comment, CreatedOn, CreatedBy )
In your DetailsView, you'll need to bind the existing comments to the bottom of the story, right? Here is an example using a repeater.
<div class="Comment">
<ul class="Comment-Items">
<asp:Repeater ID="Item" EnableViewState="True" runat="server">
<ItemTemplate>
<li class="CommentBy">
<%# Eval("CreatedBy") %> - <%# Eval("CreatedOn") %></li>
<li class="CommentText">
<%# Eval("Comment") %></li>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
Adding Comments, a few ideas...
a. Add new comment via Ajax and insert the new comment into the DOM
b. Add new comment via Ajax and return all the comments to rebind into the DOM
c. Add new comment with POSTBACK and refresh the page
Upvotes: 2