私のアプリケーションでは、データベースからデータを取得します。データベースには10個のレコードが含まれています。しかし、ページにレコードを表示しているときは、1つのレコードしか表示されません。10個のレコードニーズをすべて表示したい。セッション変数を使用してデータをページに保存および表示します。データをバインドするためのコントロールは必要ありません。データの保存と表示にセッション変数のみを使用したい。以下のimはコードを書きます。セッションストアには1つの値しかありませんが、セッションに複数の値を保存して複数のデータを表示したいのですが。
.csファイル
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ページにデータを表示しています。
ソースコード
<%@ 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>