Your code has been verified.
There is no issue.
Refer the sample.
Database
HTML
ArticleTitle
<div class="" style="width: 100%; margin: 0 auto; color: #011b33; padding: 10px;">
<div class="col-sm-11" style="margin: 0 auto; padding: 10px; width: 100%;">
<label style="color: #00003D;">Articles</label>
</div>
<div class="col-sm-10" style="margin: 0 auto; padding: 6px;">
<asp:Repeater ID="rptPages" runat="server">
<ItemTemplate>
<%# Container.ItemIndex + 1 %>.
<asp:HyperLink ID="HyperLink2" NavigateUrl='<%# string.Format("~/contents/{0}/{1}.aspx", Eval("ArticleId"), Eval("Slug")) %>'
Text='<%# Eval("Title") %>' runat="server" />
</ItemTemplate>
<SeparatorTemplate>
<br />
</SeparatorTemplate>
</asp:Repeater>
</div>
</div>
Articlecontents
<div class="" style="width: 100%; margin: 0 auto; color: #011b33; padding: 10px;">
<div class="col-sm-11" style="margin: 0 auto; padding: 10px; width: 100%;">
<label style="color: #00003D;">Detailed contents</label>
</div>
<div class="col-sm-10" style="margin: 0 auto; padding: 6px;">
<h5>
<asp:Label ID="lblTitle" runat="server" Text="Title" />
<%--<asp:Label ID="timelbl" runat="server" Text="" Font-Size="Smaller" Font-Bold="true"></asp:Label>--%>
</h5>
<hr />
<asp:Label ID="lblBody" runat="server" Text="Body" />
</div>
</div>
Namespaces
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
Code
ArticleTitle
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.PopulateArticleId();
}
}
private void PopulateArticleId()
{
string query = "SELECT [ArticleId], [Title], REPLACE([Title], ' ', '-') [SLUG], [Body] FROM [Blogs]";
using (SqlConnection con = new SqlConnection(@"server=.;DataBase=AjaxSamples;UID=sa;PWD=pass@123;"))
{
using (SqlCommand cmd = new SqlCommand(query))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
rptPages.DataSource = dt;
rptPages.DataBind();
}
}
}
}
}
Articlecontents
public partial class Articlecontents : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.PopulateArticle();
}
}
private void PopulateArticle()
{
string articleId = this.Page.RouteData.Values["ArticleId"].ToString();
string query = "SELECT [Title], [Body] FROM [Blogs] WHERE [ArticleId] = @ArticleId";
using (SqlConnection con = new SqlConnection(@"server=.;DataBase=AjaxSamples;UID=sa;PWD=pass@123;"))
{
using (SqlCommand cmd = new SqlCommand(query))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Parameters.AddWithValue("@ArticleId", articleId);
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
lblTitle.Text = dt.Rows[0]["Title"].ToString();
lblBody.Text = dt.Rows[0]["Body"].ToString();
//timelbl.Text = dt.Rows[0]["DatePosted"].ToString();
}
}
}
}
}
}
Global
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;
using System.Web.Security;
using System.Web.SessionState;
namespace Article_On_Website
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("Articlecontents", "contents/{ArticleId}/{Slug}.aspx", "~/Articlecontents.aspx");
}
}
}
Screenshot