Tuesday, September 7, 2010

Roting concept in asp,net 3.5 , 4.0

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            ShowHeader="False" onselectedindexchanged="GridView1_SelectedIndexChanged">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CommandName="select"
                            Text='<%# Eval("firstname") %>'></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                       <asp:HyperLink runat="server" ID="lnkProduct1" NavigateUrl='<%# Page.GetRouteUrl("View Product", new { ProductName = Eval("Firstname").ToString() ,Name =Eval("Lastname").ToString()}) %>' Text='<%# Eval("Firstname") %>'></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                       <asp:HyperLink runat="server" ID="lnkProduct2" NavigateUrl='<%# Page.GetRouteUrl("walia", new { walia = Eval("lastname").ToString() ,rakesh =Eval("firstname").ToString()}) %>' Text='<%# Eval("lastname") %>'></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
     
  
     
    </div>
    <p>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
     
  
     
    </p>
    </form>
</body>
</html>
--------------------------------------------------------------------------------------------------
--- cs file


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.Configuration;
using System.Data;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
            SqlDataAdapter adp = new SqlDataAdapter("select * from tblemp", con);
            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            DataSet ds = new DataSet();
            adp.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string a="walia";
        Response.Redirect (Page.GetRouteUrl ("View Product",new{ ProductName=a.ToString ()}));
        //Page.GetRouteUrl("View Product", new { ProductName = "ProductName".ToString() });
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
      
    }
}

-----------------------------------------------------------------------------------------

----global file

<%@ Application Language="C#" %>
<%@ Import Namespace="System.Web.Routing" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes(RouteTable.Routes);
        // Code that runs on application startup
    }
    void RegisterRoutes(RouteCollection routes)
    {
        // Register a route for Products/{ProductName}
        routes.MapPageRoute(
            "View Product",             // Route name
            "Indian Cricketer/{ProductName}/{Name}.go",   // Route URL
            "~/3d_Chart.aspx"        // Web page to handle route
        );
        routes.MapPageRoute("walia", "john_cena/{walia}/{rakesh}.jsp", "~/Default4.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>

No comments:

Post a Comment