try this code
database
USE [TEST]
GO
/****** Object: Table [dbo].[Articletable] Script Date: 3/19/2015 5:32:58 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Articletable](
[ID] [int] NOT NULL,
[Title] [varchar](200) NULL,
[Description] [varchar](400) NULL,
[Author] [varchar](50) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
insert some data in table
source code on URLRouting.aspx
<div>
<h1>
<span style="color: #009900">Routing Page test</span></h1>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="#DEBA84"
BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2"
Width="788px" Height="80px">
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<Columns>
<asp:TemplateField HeaderText="Title">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" CssClass="ArticleTitle" href='<%# GetRouteUrl("RouteForArticle", new {id = Eval("id"), Title= (Eval("Title"))})%>'
Text='<%# Eval("Title") %>'>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lblDesc" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Description")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Author">
<ItemTemplate>
<asp:Label ID="lblauthor" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Author")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
</asp:GridView>
</div>
c# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class URL_Rewriting : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource = GetData();
GridView1.DataBind();
}
private DataTable GetData()
{
String connectionString = ConfigurationManager.ConnectionStrings["ErpConnection"].ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
SqlDataAdapter da = new SqlDataAdapter("select Id,Title,Description,author from Articletable", conn);
DataSet ds = new DataSet();
da.Fill(ds, "MyTestTable");
return ds.Tables["MyTestTable"];
}
protected string GetTitle(object obj)
{
return obj.ToString().Replace(' ', '-');
}
}
global.asax page
<%@ Import Namespace="System.Web.Routing" %>
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routeCollection)
{
routeCollection.MapPageRoute("RouteForArticle", "Articles/{id}/{Title}", "~/DetailPage.aspx");
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
</script>
second page where redirect page from click in gridview row -customer.aspx
<div>
<h1>
Article</h1>
<b>Title:</b><asp:Label ID="lblTitle" runat="server" Text="Label" Font-Bold="true"
ForeColor="blue"></asp:Label><br />
AuthorName<b>:</b><asp:Label ID="lblauthor" runat="server" Text="Label" Font-Bold="true"
ForeColor="blue"></asp:Label>
<br />
<br />
<b>Description:</b><br />
<asp:Label ID="lblDescription" runat="server" Text="Label"></asp:Label><br />
<br />
<br />
<br />
</div>
c# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class DetailPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Page.RouteData.Values["id"].ToString() != null)
{
string strId = Page.RouteData.Values["id"].ToString();
DisplayArticle(strId);
}
}
private void DisplayArticle(string strId)
{
String connectionString = ConfigurationManager.ConnectionStrings["ErpConnection"].ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
SqlDataAdapter da = new SqlDataAdapter("select Id,Title,Description,author from Articletable where Id=" + strId, conn);
DataSet ds = new DataSet();
da.Fill(ds, "Articletable");
lblTitle.Text = ds.Tables["Articletable"].Rows[0][1].ToString();
lblDescription.Text = ds.Tables["Articletable"].Rows[0][2].ToString();
lblauthor.Text = ds.Tables["Articletable"].Rows[0][3].ToString();
}
}
connection string in webconfig
<connectionStrings>
<add name="ErpConnection" connectionString="Data Source=FUTURE1-PC\SQLEXPRESS;Initial Catalog=TEST;integrated security=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
if you want remove extenstion customer.aspx to customer
then write code in global.asax
public static void RegisterRoutes(RouteCollection routeCollection)
{
routeCollection.MapPageRoute("RouteForArticle", "customerrrrr", "~/customer.aspx");
}
and change the navigation link in gridview
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" CssClass="ArticleTitle" href='<%# GetRouteUrl("RouteForArticle", new {})%>'
Text='<%# Eval("Title") %>'>
</asp:HyperLink>
</ItemTemplate>