Saturday, 2 February 2013

Routing In ASP.NET II



Routing In ASP.NET

HttpContext context = HttpContext.Current;
String id = context.Items["AuthorID"].ToString();
to the load_page method I got problems where should I add this my code is:
                       
Global.asax:
 void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes();
    }
    private void RegisterRoutes()
    {

        System.Web.Routing.RouteTable.Routes.Add("Tutorial", new System.Web.Routing.Route(Server.MapPath("~/")+"webpages/Default5.aspx/{category}", new RouteHandler(string.Format("~/webpages/Default5.aspx"))));
   
    }
Default5.aspx:

 public String cat="fenous";
    protected void Page_Load(object sender, EventArgs e)
    {
        
        HttpContext context = HttpContext.Current;
        cat = context.Items["category"].ToString();
        Load_ListView();
    }
       void Load_ListView()
    {
        try
        {
            OleDbConnection MyCon;   // create connection
            OleDbDataAdapter com;  // create command
            // OleDbDataReader dr;  //Dataread for read data from database
            string datapath = "websitedatabase.mdb";
            string path = Server.MapPath("~/") + datapath;
            MyCon = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source=" + path + "; Jet OLEDB:Database Password=pass");
            com = new OleDbDataAdapter("Select * from images where Category='"+cat+"'", MyCon);
            MyCon.Open();                                        // open the connection
            DataSet ds = new DataSet();
            com.Fill(ds);
            ListView1.DataSource = ds;
            ListView1.DataBind();
            MyCon.Close();

        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }

No comments:

Post a Comment

Comment Here