Skip to main content

Caching:Varying the Output Cache By Parameter in ASP.NET

OutPutCacheByPrameter.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="OutPutCacheByPrameter.aspx.cs" Inherits="OutPutCacheByPrameter" %>



 



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



 



<html xmlns="http://www.w3.org/1999/xhtml">



<head runat="server">



<title>Caching; Varying the Output Cache By Parameter</title>



</head>



<body>



<form id="form1" runat="server">



<div>



<asp:GridView ID="grdEmployee" runat="server" AutoGenerateColumns="False"



ShowHeader="False">



<Columns>



<asp:HyperLinkField DataTextField="EmpName" DataNavigateUrlFields="EmpId"



DataNavigateUrlFormatString="EmployeeDetails.aspx?EmpId={0}" />



</Columns>



</asp:GridView>



</div>



</form>



</body>



</html>






Code File:





using System;



using System.Collections;



using System.Configuration;



using System.Data;



using System.Linq;



using System.Web;



using System.Web.Security;



using System.Web.UI;



using System.Web.UI.HtmlControls;



using System.Web.UI.WebControls;



using System.Web.UI.WebControls.WebParts;



using System.Xml.Linq;



using System.Data.SqlClient;



 



public partial class OutPutCacheByPrameter : System.Web.UI.Page



{



SqlConnection con;



SqlCommand cmd = new SqlCommand();



DataSet ds = new DataSet();



SqlDataAdapter da;



protected void Page_Load(object sender, EventArgs e)



{



BindData();



}



public void BindData()



{



string Appcon = ConfigurationManager.ConnectionStrings["ConnectionStr"].ConnectionString;



con = new SqlConnection(Appcon);



cmd.CommandText = "Select * from Employees";



da = new SqlDataAdapter(cmd);



cmd.Connection = con;



con.Open();



cmd.ExecuteNonQuery();



da.Fill(ds);



if (ds.Tables[0].Rows.Count > 0)



{



grdEmployee.DataSource = ds;



grdEmployee.DataBind();



}



}



}






web.config:





<connectionStrings>



<add name="ConnectionStr" connectionString="Data Source=.;Initial Catalog=asp;User Id=sa;Password=niitbpl123"/>



</connectionStrings>






Code Behind File:





using System;



using System.Collections;



using System.Configuration;



using System.Data;



using System.Linq;



using System.Web;



using System.Web.Security;



using System.Web.UI;



using System.Web.UI.HtmlControls;



using System.Web.UI.WebControls;



using System.Web.UI.WebControls.WebParts;



using System.Xml.Linq;



using System.Data.SqlClient;



 



public partial class OutPutCacheByPrameter : System.Web.UI.Page



{



SqlConnection con;



SqlCommand cmd = new SqlCommand();



DataSet ds = new DataSet();



SqlDataAdapter da;



protected void Page_Load(object sender, EventArgs e)



{



BindData();



}



public void BindData()



{



string Appcon = ConfigurationManager.ConnectionStrings["ConnectionStr"].ConnectionString;



con = new SqlConnection(Appcon);



cmd.CommandText = "Select * from Employees";



da = new SqlDataAdapter(cmd);



cmd.Connection = con;



con.Open();



cmd.ExecuteNonQuery();



da.Fill(ds);



if (ds.Tables[0].Rows.Count > 0)



{



grdEmployee.DataSource = ds;



grdEmployee.DataBind();



}



}



}






EmployeeDetails.aspx





<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EmployeeDetails.aspx.cs" Inherits="EmployeeDetails" %>



<%@ OutputCache Duration="5" VaryByParam="none" %>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



 



<html xmlns="http://www.w3.org/1999/xhtml">



<head runat="server">



<title>CACHING: Output Cache By Parameter: Employee Details</title>



</head>



<body>



<form id="form1" runat="server">



<div>



<asp:Label ID="lblTime" runat="server"></asp:Label><br />



<br />



<asp:DetailsView ID="dtlEmployee" runat="server">



</asp:DetailsView>



</div>



</form>



</body>



</html>






Code Behind File:





using System;



using System.Collections;



using System.Configuration;



using System.Data;



using System.Linq;



using System.Web;



using System.Web.Security;



using System.Web.UI;



using System.Web.UI.HtmlControls;



using System.Web.UI.WebControls;



using System.Web.UI.WebControls.WebParts;



using System.Xml.Linq;



using System.Data.SqlClient;



 



public partial class EmployeeDetails : System.Web.UI.Page



{



SqlConnection con;



SqlCommand cmd = new SqlCommand();



DataSet ds = new DataSet();



SqlDataAdapter da;



protected void Page_Load(object sender, EventArgs e)



{



lblTime.Text = System.DateTime.Now.ToString();



BindData();



}



public void BindData()



{



string Appcon = ConfigurationManager.ConnectionStrings["ConnectionStr"].ConnectionString;



con = new SqlConnection(Appcon);



cmd.CommandText = "Select * from Employees where EmpId=" + Request.Params[0].ToString();



da = new SqlDataAdapter(cmd);



cmd.Connection = con;



con.Open();



cmd.ExecuteNonQuery();



da.Fill(ds);



if (ds.Tables[0].Rows.Count > 0)



{



dtlEmployee.DataSource = ds;



dtlEmployee.DataBind();



}



}



}






Output:



1a1b

Comments

  1. We provide personal finances for debt consolidation, bad credit finances, unsecured finances, finances for bad credit and instant secured finances with cheap rates. Do you have a firm or company that need finance to start up a business or need,personal finance, Debt consolidation? For more information. We will provide you with finance to meet your needs. For more information contact.

    We offer Easy and Fast Credit facility.
    Email: royalworldfundings@gmail.com

    Note: We offer the following finances to individuals-
    Commercial finances
    Personal finances
    Business finances
    Investments finances
    Development finances
    Acquisition finances
    Construction finances
    Business finances And many More at 3% interest rate;
    Contact Us At : royalworldfundings@gmail.com

    ReplyDelete
  2. If you had financial problems, then it is time for you to smile. You only need to contact Mr. Benjamin  with the amount you wish to borrow and the payment period that suits you and you will have your loan  within three working days. I just benefited for the sixth time a loan of 700 thousand dollars for a period of 180 months with the possibility of paying before the expiration date. Mr Benjamin has be helping me with loan.Make contact with him and you will see that he is a very honest man with a good heart.His email is lfdsloans@lemeridianfds.com and his WhatApp phone number is + 1-989-394-3740 

    ReplyDelete

Post a Comment

Popular posts from this blog

C++ Program to define a Class BOOK and accessing member function using its object.

  #include<iostream.h> #include<stdio.h> #include<conio.h> class BOOK { int BOOKNO; char BOOKTITLE[20]; float PRICE; void TOTAL_COST( int N) { float tcost; tcost=PRICE*N; cout<<tcost; } public : void INPUT() { cout<<" Enter Book Number "; cin>>BOOKNO; cout<<" Enter Book Title "; gets(BOOKTITLE); cout<<" Enter price per copy "; cin>>PRICE; } void PURCHASE() { int n; cout<<" Enter number of copies to purchase "; cin>>n; cout<<" Total cost is "; TOTAL_COST(n); } }; void main() { BOOK obj; obj.INPUT(); obj.PURCHASE(); getch(); }

WAP to calculate the monthly telephone bills as per the following rule: Minimum Rs. 200 for upto 100 calls. Plus Rs. 0.60 per call for next 50 calls. Plus Rs. 0.50 per call for next 50 calls. Plus Rs. 0.40 per call for any call beyond 200 calls.

  #include<iostream.h> #include<conio.h> void main() { int calls; float bill; cout<<" Enter number of calls : "; cin>>calls; if (calls<=100) bill=200; else if (calls>100 && calls<=150) { calls=calls-100; bill=200+(0.60*calls); } else if (calls>150 && calls<=200) { calls=calls-150; bill=200+(0.60*50)+(0.50*calls); } else { calls=calls-200; bill=200+(0.60*50)+(0.50*50)+(0.40*calls); } cout<<" Your bill is Rs. "<<bill; getch(); }   Output: Enter number of calls : 190 Your bill is Rs.250

Write a program to calculate the total expenses. Quantity and price per item are input by the user and discount of 10% is offered if the expense is more than 7000.

  #include<iostream.h> #include<conio.h> void main() { int totalexp, qty, price, discount; cout<<" Enter quantity: "; cin>>qty; cout<<" Enter price: "; cin>>price; totalexp=qty*price; if (totalexp>7000) { discount=(totalexp*0.1); totalexp=totalexp-discount; } cout<<" Total Expense is Rs. "<<totalexp; getch(); }