How to enable cache in Gridview ?



Hi
Using SqldataSource or ObjectdataSource control, we can easily implement the cache concept in Gridview. If we will use the cache concept,it will avoid the server overloading and it will increase the performance of website.

We can do like this.Here i m using objectdatasource.
Step1:Create one Class i.e “GetEmp” and write the code like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;

///

/// Summary description for GetEmp
///

public class GetEmp
{
private static readonly string _ConnectionString;
public int Id { get; set; }
public string EmpName { get; set; }
public string EmpSal { get; set; }

static GetEmp()
{
_ConnectionString = WebConfigurationManager.ConnectionStrings[“Test”].ConnectionString;
}

public List GetAllEmp()
{
List result = new List();
using (SqlConnection con = new SqlConnection(_ConnectionString))
{
using (SqlCommand cmd = new SqlCommand(“Select Id,Empname,EmpSal from tblEmp”, con))
{
using (con)
{
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
GetEmp newEmp = new GetEmp();
newEmp.Id = (int)dr[“Id”];
newEmp.EmpName = (string)dr[“EmpName”];
newEmp.EmpSal = (string)dr[“EmpSal”];
result.Add(newEmp);

}

}
}
return result;
}
}
}

Step2: Take one Gridview and ObjectDatasouce Control in default page like this.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1" CellPadding="4" ForeColor="#333333">
<RowStyle BackColor="#E3EAEB" />
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" />
<asp:BoundField DataField="EmpName" HeaderText="EmpName"
SortExpression="EmpName" />
<asp:BoundField DataField="EmpSal" HeaderText="EmpSal"
SortExpression="EmpSal" />
</Columns>
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<br />
<asp:ObjectDataSource ID="ObjectDataSource1" TypeName="GetEmp" EnableCaching="true" CacheDuration="3000" SelectMethod="GetAllEmp" runat="server">
</asp:ObjectDataSource>

Step3:Now Compile the code.

Advertisements

How to detect the Phishing Email?


Hi
Yesterday I got very nice phishing Email. At first glance I thought this Email come from Microsoft hotmail site. But after some time I detected that this is the phishing Email.

What is the phishing Email?
In a general word, it is the process of acquiring sensitive information such as usernames, Password of EmailId or credit card details by sending trustworthy entity in Email.
For more information on it. Please read “What is phishing”. http://en.wikipedia.org/wiki/Phishing
They usually try get information of UserId, Password of your account. There will be lots phishing Email sample like “Without giving interview getting job in good company”,”Lottery Email”,”Credit card password expiry”,”Email Id Password expiry”,or “Quick time earn money” etc

But here is some tips, you can easily detect the phishing Email

1.Check the sender Email Id.
By seeing email Id, we can easily detect it. In my case email Id was: Kapil_gautam@hotmail.com
So we can easily tell that he is the fraud person. It will never come some mail from Hotmail team like this.

2.By reading the email content. No one email server or bank site used to take your password. This is the personal privilege of any user. So you never send reply to this type email.

3.By viewing the HTML code. If you will check the HTML code of that page or URL. You will never go the correct URL.

If you want to know more tips, then read this article also http://blog.greggman.com/blog/how_to_detect_e_mail_scams__phishing_

I hope it will help to someone.