kieky bouvier

kieky bouvier

  • NA
  • 58
  • 83.4k

How to return 0 value?

Apr 21 2011 10:07 AM
hi all...i need your help..
i'm using method to count total comment in my application.

This is my code : 

Comment.aspx
<asp:TemplateField HeaderText="Comment" ItemStyle-CssClass="GridviewItem" ItemStyle-VerticalAlign="Top"
ItemStyle-HorizontalAlign="Left" HeaderStyle-Width="15%" ItemStyle-Wrap="false">
<ItemTemplate>
<%#GetCountComment(Convert.ToString(Eval("IdTopic")))%>
</ItemTemplate>
<HeaderStyle Width="15%" />
<ItemStyle CssClass="GridviewItem" HorizontalAlign="Center" VerticalAlign="Top" Wrap="False" />
</asp:TemplateField>


Comment.aspx.cs
protected String GetCountComment(string IdTopik)
{
try
{
string value = String.Empty;

DMSDataAccess db = new DMSDataAccess();
var comment = db.DMSDataContext.Comments.Where(p => Convert.ToString(p.IdTopic) == IdTopic);

value = Convert.ToString(comment.Count());
return value;
}
catch (Exception e)
{
return e.ToString();
}
}

i think my code is correct.. but it can't display "0" value.. Can u help me to fix it??

thanks before...


Answers (33)