Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1006809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:31:08+00:00 2026-05-16T08:31:08+00:00

Just starting with ASP.NET and find it difficult to use the GridView. I have

  • 0

Just starting with ASP.NET and find it difficult to use the GridView. I have a set of Session variables which I want to put into a GridView control, but I lack the knowledge. The file:

<%@ 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>

In the code behind I want to add the session variables to the GridView1, just for display purposes. Later on it will be connected to a database, but for practice, I want to know how I can add my session variables to the GridView1. The file:

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.?
        }
    }

I might be thinking this all wrong. If I do, please correct me to the right path! Thanx for listening.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:31:08+00:00Added an answer on May 16, 2026 at 8:31 am

    It’s as simple as putting this in your Page_Load:

    // Sample to add a value to session to ensure that something is shown
    Session.Add("SessionValue1", "Value");
    
    // Actual work of binding Session to the grid
    GridView1.DataSource = Session;
    GridView1.DataBind();
    

    There’s a Microsoft Knowledge Base article that goes some way to answering your question(s) as it provides some examples of Data Binding in action and links to further articles giving additional detail.

    Assuming you had some code such as:

    var warehouseItems = 
        from item in DataTableContainingWarehouseItems.AsEnumerable()
        select
        new
        {
            InventoryName = item.Field<string>("Name"),
            InventoryValue = item.Field<int>("Value"),
            InventoryPrice = item.Field<decimal>("Price"),
            StockOnHandValue = Convert.ToDecimal(item.Field<int>("Value") * item.Field<decimal>("Price"))
        };
    

    You could then bind directly to that:

    GridView1.DataSource = warehouseItems;
    GridView1.DataBind();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just starting to use the ASP.NET GridView control. I was thinking of adding
i'm just starting to use asp.net mvc.. since i'm not familiar with it, i
I'm new to ASP.NET and have just starting to learn ASP.NET MVC 3. I've
I've been working in ASP.NET- just starting out, and I have a pretty simple
I'm just starting to pick up ASP.Net MVC and find myself writing a lot
Just starting out in asp.net. Have just created a login.aspx page in my site
Just starting out in ASP.NET MVC - I have a page in ASP.NET MVC3
I'm just starting to use the Telerik asp.net mvc and I'm stuck on trying
I am just starting porting an application to ASP.net MVC and I have an
Just starting to learn ASP.NET (C#) and I am using Visual Studio 2008. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.