在我的应用程序中,我从数据库中检索数据.在数据库中包含10条记录.但是当我在页面中显示记录时,它仅显示一个记录.我希望显示所有10条记录针.我正在使用会话变量在page中存储和显示数据.我不想任何控件来绑定数据.我只希望将会话变量用于存储和显示数据.下面我写代码.我知道会话仅存储一个值,但是我希望会话存储多个值并显示多个数据. .cs文件
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(); } }在这里,我在aspx页面中显示数据. 源代码
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>推荐答案
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
只需将数据表存储在会话中即可.然后引用所需的行.无法创建具有所需值的列表或数组并将其存储.. 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..
更多推荐
在会话变量中分配多个数据
发布评论