Asp.net sample webpage for news and event
Here is a sample ASP.NET webpage for news and events:
News and Events Page
ASPX Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NewsAndEvents.aspx.cs" Inherits="NewsAndEvents" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>News and Events</title>
<style>
.news-item {
border-bottom: 1px solid #ccc;
padding: 10px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>News and Events</h1>
<asp:Repeater ID="newsRepeater" runat="server">
<ItemTemplate>
<div class="news-item">
<h2><%# Eval("Title") %></h2>
<p><%# Eval("Description") %></p>
<p><%# Eval("Date") %></p>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
Code-Behind (C#):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class NewsAndEvents : Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Load news data from database or other source
List<NewsItem> newsItems = GetNewsItems();
// Bind data to repeater
newsRepeater.DataSource = newsItems;
newsRepeater.DataBind();
}
private List<NewsItem> GetNewsItems()
{
// Replace with your own data retrieval logic
List<NewsItem> newsItems = new List<NewsItem>();
newsItems.Add(new NewsItem { Title = "News Item 1", Description = "This is the description of news item 1", Date = DateTime.Now });
newsItems.Add(new NewsItem { Title = "News Item 2", Description = "This is the description of news item 2", Date = DateTime.Now.AddDays(1) });
newsItems.Add(new NewsItem { Title = "News Item 3", Description = "This is the description of news item 3", Date = DateTime.Now.AddDays(2) });
return newsItems;
}
public class NewsItem
{
public string Title { get; set; }
public string Description { get; set; }
public DateTime Date { get; set; }
}
}
Explanation:
- The ASPX code defines a simple webpage with a heading and a repeater control to display news items.
- The code-behind class (
NewsAndEvents
) loads news data from a database or other source using theGetNewsItems()
method. - The
GetNewsItems()
method returns a list ofNewsItem
objects, which are then bound to the repeater control using theDataSource
andDataBind()
methods. - The repeater control is configured to display each news item as a separate HTML element, with properties like
Title
,Description
, andDate
displayed as text.
Note: This is a very basic example, and you will likely want to add more features, such as pagination, filtering, and sorting, to your news and events page. Additionally, you will need to replace the GetNewsItems()
method with your own data retrieval logic.