我正在尝试将一个 vbscript 会话变量传递给我的 c# 页面。经过研究,我发现了这个页面:
我不知道如何改变我的
Int32 intresortID = Convert.ToInt32(Request.QueryString["TypeID"]);
以与上面链接中提供的代码相同的方式读取会话变量(粘贴在下面:)
<TITLE>ASPNETPage1.aspx</TITLE>
<%@ Page language="c#" %>
<script runat=server>
// We iterate through the Form collection and assign the names and values
// to ASP.NET session variables! We have another Session Variable, "DestPage"
// that tells us where to go after taking care of our business...
private void Page_Load(object sender, System.EventArgs e)
{
for(int i=0;i<Request.Form.Count;i++)
{
Session[Request.Form.GetKey(i)]=Request.Form[i].ToString();
}
Server.Transfer(Session["DestPage"].ToString(),true);
}
</script>
==================================================== ==============================
<TITLE>FinalPage.aspx</TITLE>
<%@ Page language="c#" %>
<script runat=server>
// This page is just a "proof of concept page"...
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("Shared Session Variable Names/Values between Classic ASP and ASP.NET:<BR>");
for (int i = 0; i < Session.Contents.Count; i++)
{
Response.Write("Assigned to \"" +Session.Keys[i].ToString()+"\"");
Response.Write(" Value: "+ Session[i].ToString() +"<BR>");
}
}
</script>
更新:在 C# 页面上调用会话变量的代码:
private void FillGrid()
{
string connStr = ConfigurationManager.ConnectionStrings["bdsConnectionString"].ConnectionString;
using (SqlConnection Con = new SqlConnection(connStr))
{
Con.Open();
Int32 intresortID = Convert.ToInt32(Request.Form["TypeID"]);
Label4.Text = Convert.ToString(intresortID);
Label4.Visible = true;
DateTime startdate;
startdate = Convert.ToDateTime(TextBox1.Text);
Int32 ed = Convert.ToInt32(TextBox2.Text);
DateTime enddate;
enddate = startdate.AddDays(ed);
string str = "SELECT TOP (100) PERCENT tblAvail.dtm as Dtm, tblResortsRooms.strRoomType as strRoomType, tblResortsRooms.strDescription as strDescription, tblAvail.intQty as intQty, tblAvail.curPrice as curPrice, tblResortsRooms.intWSCode as intWSCode FROM tblAvail INNER JOIN tblResortsRooms ON tblAvail.intResortID = tblResortsRooms.intResortID AND tblAvail.strRoomType = tblResortsRooms.strRoomType WHERE (tblResortsRooms.curRecRate > 0) AND (tblAvail.intResortID = @intResortID) and (tblAvail.dtm between @startdate and @enddate) ORDER BY tblResortsRooms.strRoomType";
SqlDataAdapter sdr = new SqlDataAdapter(str, Con);
sdr.SelectCommand.Parameters.AddWithValue("@intResortID", intresortID);
sdr.SelectCommand.Parameters.AddWithValue("@startdate", startdate);
sdr.SelectCommand.Parameters.AddWithValue("@enddate", enddate);
DataTable dt = new DataTable();
sdr.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
Button2.Visible = true;
}
}
}
有人可以告诉我怎么做吗?