In the following code
protected void Page_Load(object sender, EventArgs e)
{
List<string> listSetValues = Class1.categories();
foreach (string strTemp in listSetValues)
{
DIV1.Controls.Add(new LiteralControl("<li>" + strTemp + "</li>"));
}
}
and class code is
protected static List<string> listSetValues = new List<string>();
public static List<string> categories()
{
cmd = new SqlCommand("SELECT * FROM category", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
listSetValues.Add(dr[0].ToString());
}
con.Close();
return listSetValues;
}
Database table category consists of
Mobiles
DVD players
Cameras
Laptops
Televisions
Upon loading page all the above are being displayed in my website but on reloading the above five values are displayed for twice and on every reload the set of 5 values is keep on increasing.
For this, You have to initialize the List each time upon loading…..
In method code,