在会话变量中分配多个数据

编程入门 行业动态 更新时间:2024-10-23 11:22:57
本文介绍了在会话变量中分配多个数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的应用程序中,我从数据库中检索数据.在数据库中包含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..

更多推荐

在会话变量中分配多个数据

本文发布于:2023-10-27 03:23:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1532173.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   变量   分配   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!