【发布时间】:2010-08-18 07:50:47
【问题描述】:
刚开始使用 ASP.NET,发现很难使用 GridView。我有一组会话变量,我想将它们放入 GridView 控件中,但我缺乏相关知识。文件:
<%@ Page Title="Warehouse" Language="C#" AutoEventWireup="true"
MasterPageFile="~/Site.master"
CodeFile="Warehouse.aspx.cs" Inherits="Warehouse" %>
<asp:Content ID="HeaderContent" runat="server"
ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Warehouse
</h2>
<asp:Panel ID="WarehousePanel" runat="server">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</asp:Panel>
</asp:Content>
在后面的代码中,我想将会话变量添加到 GridView1,仅用于显示目的。稍后它将连接到数据库,但为了练习,我想知道如何将会话变量添加到 GridView1。文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Warehouse : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["milk"] == null)
Session["milk"] = "0";
if (Session["apple"] == null)
Session["apple"] = "0";
if (Session["orange"] == null)
Session["orange"] = "0";
// on page load, add session variables ie Session["milk"].ToString();
// column 1: inventory name
// column 2: inventory value
GridView1.?
}
}
我可能认为这一切都错了。如果我这样做,请纠正我正确的道路!感谢收听。
【问题讨论】:
-
你还没有真正得到什么,我建议你多读书。
标签: c# asp.net gridview session-variables