Click here to Skip to main content
15,922,419 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
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>
Posted

XML
Session["divhtml_heading1"]="";
foreach (DataRow dr in ds.Tables[0].Rows)

        {
            Session["divhtml_heading1"] = Session["divhtml_heading1"] +"<br>" + dr["divhtml_content"].ToString();

        }

use this code perhaps it will help you
 
Share this answer
 
Comments
Manohar Khillare 18-Jun-12 5:49am    
Thanks Porsan It will really help for me great logic . it solved my problem. i want to ask u is there any other better way to display data.means my TL acccept this solution but he want different logic for display data.
Just store the datatable in session. Then reference the line you want. Failing that create a list or array with the values you want and store that..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900