In my application i m retrive data from database. In database contain 10 records. but when i am display record in page it display only one record. i want all 10 record neeeds to be display. i m using session variable to store and display data in page . i dont want any control to bind data. i want only session variable to be used to store and display data . below i m write code. i know session store only one value but i want session store multiple value and display multiple data.
.cs file
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=Aarambh;Initial Catalog=rebuild_technology;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select * from content_managment ", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
foreach (DataRow dr in ds.Tables[0].Rows)
{
Session["divhtml_heading1"] = dr["divhtml_content"].ToString();
}
}
Here i am display data in aspx page.
Source code
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Home" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<% Response.Write(Session["divhtml_heading1"].ToString()); %>
</asp:Content>
I would recommend to store all database contents in Custom object like
Store contents in it in foreach loop like
You populate lstOfDivHtml in the forloop & then set it in session once after the for loop like
And when you display the contents on page, retrieve lstofDivHtml from Session & display it in loop
P.S.
On Page markup or codebehind
Cant be more specific than this now 🙂