How to display latest news in the webpage using asp.net with c#?
Solution 1
The latest news has to stored in database, generally newsid(auto generating), news date, posted by, news title and news content are the fields required in latest news table. In admin side of the website create a page to insert/edit/delete latest news. In home page display top 'n' number of latest news by using the query 'select newsdate,newstitle from latestnews order by newsdate desc' so that you can be able to view the most latest news. Using repeater control you can display the latest news so that it does not appear in table structure like gridview. Take a look at the code below, on clicking a news title you have to redirect to view detailed news page wherein you have to display the title, full content, date, etc.,
<asp:Repeater ID="repeaterLatestNews" OnItemDataBound="repeaterLatestNews_ItemDataBound"
runat="server">
<ItemTemplate>
<table>
<tr>
<td class="currentnewspanel1dateNew">
<%# DataBinder.Eval(Container.DataItem, "newsdate")%>
</td>
<td>
<asp:HiddenField ID="hdnNewsID" Value='<%# DataBinder.Eval(Container.DataItem, "NewsAndEventId") %>'
runat="server" />
</td>
<td class="currentnewspanel1date-contentNew">
<a href="Common/ViewLatestNews.aspx" id="aNewsContent" cssclass="currentnewspanel1date-contentNew"
runat="server">
<%# DataBinder.Eval(Container.DataItem, "NewsTitle")%></a>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
<asp:Repeater ID="repeaterLatestNews" OnItemDataBound="repeaterLatestNews_ItemDataBound"
runat="server">
<ItemTemplate>
<table>
<tr>
<td class="currentnewspanel1dateNew">
<%# DataBinder.Eval(Container.DataItem, "newsdate")%>
</td>
<td>
<asp:HiddenField ID="hdnNewsID" Value='<%# DataBinder.Eval(Container.DataItem, "NewsAndEventId") %>'
runat="server" />
</td>
<td class="currentnewspanel1date-contentNew">
<a href="Common/ViewLatestNews.aspx" id="aNewsContent" cssclass="currentnewspanel1date-contentNew"
runat="server">
<%# DataBinder.Eval(Container.DataItem, "NewsTitle")%></a>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
Solution2
By using timer control with ajax, we can display the latest news.
In News page, add script manager,timer control.
Set the time for refresh the latest news content.After that add the latest news content data within the update panel control.Add trigger off timerTick event to this update panel.
In code behind, on timerTick event load the news content...
sample:
in news.aspx
<asp:Timer ID="Timer1" runat="server" Interval="1000">
</asp:Timer>
<asp:UpdatePanel ID="up_LatestNews" runat="server">
<ContentTemplate>
//here list the latest news
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
in news.aspx.cs:
protected void Timer1_Tick(object sender, EventArgs e)
{
//here call the latest news loading method..
}
I hope u get the idea about displaying latest news.
In News page, add script manager,timer control.
Set the time for refresh the latest news content.After that add the latest news content data within the update panel control.Add trigger off timerTick event to this update panel.
In code behind, on timerTick event load the news content...
sample:
in news.aspx
<asp:Timer ID="Timer1" runat="server" Interval="1000">
</asp:Timer>
<asp:UpdatePanel ID="up_LatestNews" runat="server">
<ContentTemplate>
//here list the latest news
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
in news.aspx.cs:
protected void Timer1_Tick(object sender, EventArgs e)
{
//here call the latest news loading method..
}
I hope u get the idea about displaying latest news.
No comments:
Post a Comment