首页 > 代码库 > 数据控件中session传值的使用实例
数据控件中session传值的使用实例
显示页设置where条件session["CID"]
.aspx代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="news_id" DataSourceID="AccessDataSource1">
<Columns>
<asp:BoundField DataField="news_id" HeaderText="news_id" InsertVisible="False"
ReadOnly="True" SortExpression="news_id" />
<asp:BoundField DataField="news_ttl" HeaderText="news_ttl"
SortExpression="news_ttl" />
<asp:BoundField DataField="news_date" HeaderText="news_date"
SortExpression="news_date" />
<asp:BoundField DataField="news_content" HeaderText="news_content"
SortExpression="news_content" />
<asp:CheckBoxField DataField="news_enable" HeaderText="news_enable"
SortExpression="news_enable" />
<asp:BoundField DataField="news_order" HeaderText="news_order"
SortExpression="news_order" />
<asp:BoundField DataField="news_cid" HeaderText="news_cid"
SortExpression="news_cid" />
<asp:BoundField DataField="news_picsrc" HeaderText="news_picsrc"
SortExpression="news_picsrc" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/mdb/mydb.mdb"
SelectCommand="SELECT * FROM [tb_news] WHERE ([news_cid] = ?)">
<SelectParameters>
<asp:SessionParameter DefaultValue=http://www.mamicode.com/"1" Name="news_cid" SessionField="CID"
Type="Int32" />
</SelectParameters>
</asp:AccessDataSource>
</div>
</form>
</body>
</html>
链接页代码如下:
.aspx代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:BulletedList ID="BulletedList1" runat="server"
DataSourceID="AccessDataSource1" DataTextField="lnc_name"
DataValueField="lnc_id" DisplayMode="LinkButton" onclick="BulletedList1_Click">
</asp:BulletedList>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/mdb/mydb.mdb"
SelectCommand="SELECT [lnc_id], [lnc_name] FROM [list_newsclass]">
</asp:AccessDataSource>
</div>
</form>
</body>
</html>
.aspx.cs代码如下:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void BulletedList1_Click(object sender, BulletedListEventArgs e) { Session["CID"] = BulletedList1.Items[e.Index].Value; Response.Redirect("Default.aspx"); } }
数据控件中session传值的使用实例