The name 'lblTotal' does not exist in the current context

I am not a c# programmer, and I have searched the hundreds of articles here and on the  ms knowledge-base that concern this message and can't seem to fix it. The code is copied and pasted from my professor into an asp.net project, so it seems that might be part of the problem.

Help please.
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Web.Security;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Shopcart : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if ((string)Request.QueryString["id"] != "")
        {
            string strSongID = ""; //declare a local variable strSongID
            strSongID = (string)Request.QueryString["id"];
            if (Request.QueryString["action"] == "'add'")
            {
                AddItem(strSongID);
            }
            else if ((string)Request.QueryString["action"] == "'more'")
            {
                //Todo
                MoreItem(strSongID);
            }
            else if ((string)Request.QueryString["action"] == "'less'")
            {
                //Todo
                LessItem(strSongID);
            }
            else if ((string)Request.QueryString["action"] == "'del'")
            {
                //Todo
                DeleteItem(strSongID);
            }
            else //must be "show" items in the shopcart
            {
                //Todo
                ShowItems();
            }
        }
        //Calculate shopcart total value
        CalcTotal();

    } //end of Page_Load()

    void AddItem(string strSongID)
    {
        //declare and initialize connection object to connect to the database
        SqlConnection conn = new SqlConnection(
            WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlCommand cmd; //declare a command object that will be used to send commands to database.
        SqlParameter shopCartIDParam; //declare a parameter object that will be passed to a stored procedure 
        SqlParameter userIDParam; //declare another parameter object

        conn.Open(); //open a connection to the database
        cmd = conn.CreateCommand(); //create a command object

        //Check if this is the first time to enter an item into shopcart
        if (Session["shopCartID"] == null)
        {
            //This is the first item to be added into the shopcart;
            //so, create a new shopcart record. We will use pNewShopCart() stored procedure
            //to create a new record in shopcart table.
            //pNewShopcart() takes two parameters: @shopcartID (output) and @userID (input)
            shopCartIDParam = new SqlParameter();
            shopCartIDParam.ParameterName = "@ShopcartID";
            shopCartIDParam.SqlDbType = SqlDbType.Int;
            shopCartIDParam.Direction = ParameterDirection.Output;

            userIDParam = new SqlParameter();
            userIDParam.ParameterName = "@UserID";
            userIDParam.SqlDbType = SqlDbType.UniqueIdentifier;
            userIDParam.Direction = ParameterDirection.Input;

            //check if user is login
            if ((string)Session["userName"] != null)
            {
                //user is login. Get the userID of this user and pass it as an input parameter
                //to the pNewShopcart() stored procedure.
                MembershipUser usr = Membership.GetUser((string)Session["userName"]);
                userIDParam.Value = usr.ProviderUserKey;
            }
            else //user is not login
            {
                //temporary code for testing only
                MembershipUser usr = Membership.GetUser("user02");
                userIDParam.Value = usr.ProviderUserKey;
                //userIDParam.Value = Guid.Empty;
            }

            cmd.Parameters.Add(shopCartIDParam); //add the first parameter
            cmd.Parameters.Add(userIDParam); //add the second parameter
            cmd.CommandText = "pNewShopCart";  //this is the name of the stored procedure
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.ExecuteNonQuery(); //send the command to execute the stored procedure

            //get the newly generated shopcartID from the output parameter and store it in
            //a session variable. This way, we can use it later as a foreign key in ShopcartLine table
            Session["shopCartID"] = (int)shopCartIDParam.Value;

            //Add an item into ShopcartLine table
            cmd.CommandText = "Insert into Shopcartline Values (" + Session["shopCartID"] + ", " + strSongID + ", 1)";
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
            conn.Close();
        }
        else //shopcart was already created. We need to add an item into an existing shopcart
        //Check if incoming SongID is already in the shopcart. If it is, simply increment the quantity by one
        //else, insert a new row.
        {
            cmd.CommandText = "Select * from Shopcartline where ShopcartID = " + Session["ShopCartID"] + " and SongID = " + strSongID;
            cmd.CommandType = CommandType.Text;
            SqlDataReader shopCartLineReader;
            shopCartLineReader = cmd.ExecuteReader();

            if (shopCartLineReader.HasRows)
            {
                shopCartLineReader.Close();
                cmd.CommandText = "Update ShopcartLine set Quantity = Quantity + 1 Where ShopCartID = " + Session["ShopCartID"] + " and SongID = " + strSongID;
                cmd.CommandType = CommandType.Text;
                cmd.ExecuteNonQuery();
            }
            else
            {
                shopCartLineReader.Close();
                //Add an item into ShopcartLine table
                cmd.CommandText = "Insert into Shopcartline Values (" + Session["ShopCartID"] + ", " + strSongID + ", 1)";
                cmd.CommandType = CommandType.Text;
                cmd.ExecuteNonQuery();
            }
            conn.Close();
        }
    } //end of AddItem()

    //Increment the quantity of an item in the shopcart
    void MoreItem(string strSongID)
    {
        //declare and initialize connection object to connect to the database
        SqlConnection conn = new SqlConnection(
            WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlCommand cmd; //declare a command object that will be used to send commands to database.
        conn.Open(); //open a connection to the database
        cmd = conn.CreateCommand(); //create a command object

        cmd.CommandText = "Update ShopcartLine set Quantity = Quantity + 1 Where ShopCartID = " + Session["ShopCartID"] + " and SongID = " + strSongID;
        cmd.CommandType = CommandType.Text;
        cmd.ExecuteNonQuery();

        conn.Close();

    } //end of MoreItem()

    //Decrement the quantity of an item in the shopcart.
    //Check if the current quantity is greater than one. If so, decrement the quantity.
    //If the current quantity is one, remove the item from shopcart.
    void LessItem(string strSongID)
    {
        //declare and initialize connection object to connect to the database
        SqlConnection conn = new SqlConnection(
            WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlCommand cmd; //declare a command object that will be used to send commands to database.
        conn.Open();
        cmd = conn.CreateCommand();

        cmd.CommandText = "Select * from Shopcartline where ShopcartID = " + Session["shopCartID"] + " and SongID = " + strSongID + " and Quantity > 1";
        cmd.CommandType = CommandType.Text;
        SqlDataReader shopCartLineReader;
        shopCartLineReader = cmd.ExecuteReader();

        if (shopCartLineReader.HasRows)
        {
            shopCartLineReader.Close();
            cmd.CommandText = "Update ShopcartLine set Quantity = Quantity - 1 Where ShopCartID = " + Session["shopCartID"] + " and SongID = " + strSongID;
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
        }
        else
        {
            shopCartLineReader.Close();
            //Delete the item from ShopcartLine table
            cmd.CommandText = "Delete from Shopcartline Where ShopCartID = " + Session["ShopCartID"] + " and SongID = " + strSongID;
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
        }
        conn.Close();

    } //end of LessItem()


    void DeleteItem(string strSongID)
    {
        //declare and initialize connection object to connect to the database
        SqlConnection conn = new SqlConnection(
            WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlCommand cmd; //declare a command object that will be used to send commands to database.
        conn.Open(); //open a connection to the database
        cmd = conn.CreateCommand(); //create a command object

        //Delete the item from ShopcartLine table
        cmd.CommandText = "Delete from Shopcartline Where ShopCartID = " + Session["ShopCartID"] + " and SongID = " + strSongID;
        cmd.CommandType = CommandType.Text;
        cmd.ExecuteNonQuery();
        conn.Close();
    } //end of DeleteItem()

    void ShowItems()
    {
        //Todo

    } //end of ShowItems()

    void CalcTotal()
    {
        //Todo
        //declare and initialize connection object to connect to the database
        SqlConnection conn = new SqlConnection(
            WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlCommand cmd; //declare a command object that will be used to send commands to database.
      
        conn.Open();
        cmd = conn.CreateCommand();
        cmd.CommandText = "Select Sum(Quantity*Listprice) " +
            "From Shopcartline as SHL inner join Song as S on SHL.SongID = S.SongID " +
            "Where ShopcartID = " + Session["shopCartID"];
        cmd.CommandType = CommandType.Text;

        //declare an SqlDataReader variable
        SqlDataReader dataReader;
        dataReader = cmd.ExecuteReader();
        
        if (dataReader.HasRows)
        {
            dataReader.Read();
            lblTotal.Text = dataReader.GetValue(0).ToString();
        }
        else
        {
            lblTotal.Text = "";
        }
        conn.Close();
    }

} //end of partial class shopcart

Open in new window

sukotto100Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
I'm not a web developer but the message is telling you that it can't find "lblTotal" in the current class.  Most likely you just need to add a Label to your page and change its name to "lblTotal".
0
SameerJagdaleCommented:
make sure your webform holds a label with name 'lblTotal', if not just drag and drop a lable control and name it - lbltotal.
0
dshrivallabhCommented:
May be you are showing the total no of songs ...in the footer part of the table...and you do not have a label there with the name lblTotal... put that label in there and it should work...moreover if the label is not there then this code should not compile and must give you compile time error in VS IDE
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

sukotto100Author Commented:
I'm sorry, I should have posted the asp, it probably would have saved you some time. I have a label, which I have tried to delete and re-add, to no avail:


</asp:GridView>
    
    <br/>
    <asp:Label ID="lblSum" runat="server" Text="Total Purchase: $"></asp:Label>
    <asp:Label ID="lblTotal" runat="server" Text=""></asp:Label>
    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/browseAll.aspx">Continue Shopping</asp:HyperLink>
   
</asp:Content>

Open in new window

0
guru_samiCommented:
can you post both your files .aspx and.aspx.cs as an attachment here....
0
sukotto100Author Commented:
Gladly:
<%@ Page Title="" Language="C#" MasterPageFile="~/Master.master" AutoEventWireup="true" CodeFile="shopcart.aspx.cs" Inherits="shopcart" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        SelectCommand="SELECT * FROM [vShopcart] WHERE ([shopcartid] = @shopcartid)">
        <SelectParameters>
            <asp:SessionParameter Name="shopcartid" SessionField="shopcartID" 
                Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataSourceID="SqlDataSource1" 
        EmptyDataText="Sorry, no item in the shopcart." BackColor="White" 
        BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" CellPadding="4" 
        GridLines="Horizontal">
        <RowStyle BackColor="White" ForeColor="#333333" />
        <Columns>
            <asp:BoundField DataField="shopcartid" HeaderText="shopcartid" 
                SortExpression="shopcartid" Visible="False" />
            <asp:BoundField DataField="quantity" HeaderText="quantity" 
                SortExpression="quantity" />
            <asp:BoundField DataField="SongID" HeaderText="SongID" 
                SortExpression="SongID" />
            <asp:BoundField DataField="title" HeaderText="title" SortExpression="title" />
            <asp:BoundField DataField="Artist" HeaderText="Artist" 
                SortExpression="Artist" />
            <asp:BoundField DataField="listprice" HeaderText="listprice" 
                SortExpression="listprice" />
            <asp:BoundField DataField="clipname" HeaderText="clipname" 
                SortExpression="clipname" />
            <asp:BoundField DataField="subtotal" HeaderText="subtotal" ReadOnly="True" 
                SortExpression="subtotal" />
            <asp:HyperLinkField DataNavigateUrlFields="SongID" 
                DataNavigateUrlFormatString="~\shopcart.aspx?id={0}&amp;action='more'" 
                HeaderText="More" Text="[+1]" />
            <asp:HyperLinkField DataNavigateUrlFields="SongID" 
                DataNavigateUrlFormatString="~\shopcart.aspx?id={0}&amp;action='less'" 
                HeaderText="Less" Text="[-1]" />
            <asp:HyperLinkField DataNavigateUrlFields="SongID" 
                DataNavigateUrlFormatString="~\shopcart.aspx?id={0}&amp;action='del'" 
                HeaderText="Delete" Text="Remove" />
        </Columns>
        <FooterStyle BackColor="White" ForeColor="#333333" />
        <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
    </asp:GridView>
    
    <br/>
    <asp:Label ID="lblSum" runat="server" Text="Total Purchase: $"></asp:Label>
    <asp:Label ID="lblTotal" runat="server" Text=""></asp:Label>
    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/browseAll.aspx">Continue Shopping</asp:HyperLink>
   
</asp:Content>

Open in new window

0
sukotto100Author Commented:
More:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Web.Security;
//using System.Collections.Generic;
//using System.Linq;
//using System.Web;
//using System.Web.UI;
//using System.Web.UI.WebControls;

public partial class Shopcart : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if ((string)Request.QueryString["id"] != "")
        {
            string strSongID = ""; //declare a local variable strSongID
            strSongID = (string)Request.QueryString["id"];
            if (Request.QueryString["action"] == "'add'")
            {
                AddItem(strSongID);
            }
            else if ((string)Request.QueryString["action"] == "'more'")
            {
                //Todo
                MoreItem(strSongID);
            }
            else if ((string)Request.QueryString["action"] == "'less'")
            {
                //Todo
                LessItem(strSongID);
            }
            else if ((string)Request.QueryString["action"] == "'del'")
            {
                //Todo
                DeleteItem(strSongID);
            }
            else //must be "show" items in the shopcart
            {
                //Todo
                ShowItems();
            }
        }
        //Calculate shopcart total value
        CalcTotal();

    } //end of Page_Load()

    void AddItem(string strSongID)
    {
        //declare and initialize connection object to connect to the database
        SqlConnection conn = new SqlConnection(
            WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlCommand cmd; //declare a command object that will be used to send commands to database.
        SqlParameter shopCartIDParam; //declare a parameter object that will be passed to a stored procedure 
        SqlParameter userIDParam; //declare another parameter object

        conn.Open(); //open a connection to the database
        cmd = conn.CreateCommand(); //create a command object

        //Check if this is the first time to enter an item into shopcart
        if (Session["shopCartID"] == null)
        {
            //This is the first item to be added into the shopcart;
            //so, create a new shopcart record. We will use pNewShopCart() stored procedure
            //to create a new record in shopcart table.
            //pNewShopcart() takes two parameters: @shopcartID (output) and @userID (input)
            shopCartIDParam = new SqlParameter();
            shopCartIDParam.ParameterName = "@ShopcartID";
            shopCartIDParam.SqlDbType = SqlDbType.Int;
            shopCartIDParam.Direction = ParameterDirection.Output;

            userIDParam = new SqlParameter();
            userIDParam.ParameterName = "@UserID";
            userIDParam.SqlDbType = SqlDbType.UniqueIdentifier;
            userIDParam.Direction = ParameterDirection.Input;

            //check if user is login
            if ((string)Session["userName"] != null)
            {
                //user is login. Get the userID of this user and pass it as an input parameter
                //to the pNewShopcart() stored procedure.
                MembershipUser usr = Membership.GetUser((string)Session["userName"]);
                userIDParam.Value = usr.ProviderUserKey;
            }
            else //user is not login
            {
                //temporary code for testing only
                MembershipUser usr = Membership.GetUser("user02");
                userIDParam.Value = usr.ProviderUserKey;
                //userIDParam.Value = Guid.Empty;
            }

            cmd.Parameters.Add(shopCartIDParam); //add the first parameter
            cmd.Parameters.Add(userIDParam); //add the second parameter
            cmd.CommandText = "pNewShopCart";  //this is the name of the stored procedure
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.ExecuteNonQuery(); //send the command to execute the stored procedure

            //get the newly generated shopcartID from the output parameter and store it in
            //a session variable. This way, we can use it later as a foreign key in ShopcartLine table
            Session["shopCartID"] = (int)shopCartIDParam.Value;

            //Add an item into ShopcartLine table
            cmd.CommandText = "Insert into Shopcartline Values (" + Session["shopCartID"] + ", " + strSongID + ", 1)";
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
            conn.Close();
        }
        else //shopcart was already created. We need to add an item into an existing shopcart
        //Check if incoming SongID is already in the shopcart. If it is, simply increment the quantity by one
        //else, insert a new row.
        {
            cmd.CommandText = "Select * from Shopcartline where ShopcartID = " + Session["ShopCartID"] + " and SongID = " + strSongID;
            cmd.CommandType = CommandType.Text;
            SqlDataReader shopCartLineReader;
            shopCartLineReader = cmd.ExecuteReader();

            if (shopCartLineReader.HasRows)
            {
                shopCartLineReader.Close();
                cmd.CommandText = "Update ShopcartLine set Quantity = Quantity + 1 Where ShopCartID = " + Session["ShopCartID"] + " and SongID = " + strSongID;
                cmd.CommandType = CommandType.Text;
                cmd.ExecuteNonQuery();
            }
            else
            {
                shopCartLineReader.Close();
                //Add an item into ShopcartLine table
                cmd.CommandText = "Insert into Shopcartline Values (" + Session["ShopCartID"] + ", " + strSongID + ", 1)";
                cmd.CommandType = CommandType.Text;
                cmd.ExecuteNonQuery();
            }
            conn.Close();
        }
    } //end of AddItem()

    //Increment the quantity of an item in the shopcart
    void MoreItem(string strSongID)
    {
        //declare and initialize connection object to connect to the database
        SqlConnection conn = new SqlConnection(
            WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlCommand cmd; //declare a command object that will be used to send commands to database.
        conn.Open(); //open a connection to the database
        cmd = conn.CreateCommand(); //create a command object

        cmd.CommandText = "Update ShopcartLine set Quantity = Quantity + 1 Where ShopCartID = " + Session["ShopCartID"] + " and SongID = " + strSongID;
        cmd.CommandType = CommandType.Text;
        cmd.ExecuteNonQuery();

        conn.Close();

    } //end of MoreItem()

    //Decrement the quantity of an item in the shopcart.
    //Check if the current quantity is greater than one. If so, decrement the quantity.
    //If the current quantity is one, remove the item from shopcart.
    void LessItem(string strSongID)
    {
        //declare and initialize connection object to connect to the database
        SqlConnection conn = new SqlConnection(
            WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlCommand cmd; //declare a command object that will be used to send commands to database.
        conn.Open();
        cmd = conn.CreateCommand();

        cmd.CommandText = "Select * from Shopcartline where ShopcartID = " + Session["shopCartID"] + " and SongID = " + strSongID + " and Quantity > 1";
        cmd.CommandType = CommandType.Text;
        SqlDataReader shopCartLineReader;
        shopCartLineReader = cmd.ExecuteReader();

        if (shopCartLineReader.HasRows)
        {
            shopCartLineReader.Close();
            cmd.CommandText = "Update ShopcartLine set Quantity = Quantity - 1 Where ShopCartID = " + Session["shopCartID"] + " and SongID = " + strSongID;
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
        }
        else
        {
            shopCartLineReader.Close();
            //Delete the item from ShopcartLine table
            cmd.CommandText = "Delete from Shopcartline Where ShopCartID = " + Session["ShopCartID"] + " and SongID = " + strSongID;
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
        }
        conn.Close();

    } //end of LessItem()


    void DeleteItem(string strSongID)
    {
        //declare and initialize connection object to connect to the database
        SqlConnection conn = new SqlConnection(
            WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlCommand cmd; //declare a command object that will be used to send commands to database.
        conn.Open(); //open a connection to the database
        cmd = conn.CreateCommand(); //create a command object

        //Delete the item from ShopcartLine table
        cmd.CommandText = "Delete from Shopcartline Where ShopCartID = " + Session["ShopCartID"] + " and SongID = " + strSongID;
        cmd.CommandType = CommandType.Text;
        cmd.ExecuteNonQuery();
        conn.Close();
    } //end of DeleteItem()

    void ShowItems()
    {
        //Todo

    } //end of ShowItems()

    void CalcTotal()
    {
        //Todo
        //declare and initialize connection object to connect to the database
        SqlConnection conn = new SqlConnection(
            WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlCommand cmd; //declare a command object that will be used to send commands to database.
       
        conn.Open();
        cmd = conn.CreateCommand();
        cmd.CommandText = "Select Sum(Quantity*Listprice) " +
            "From Shopcartline as SHL inner join Song as S on SHL.SongID = S.SongID " +
            "Where ShopcartID = " + Session["shopCartID"];
        cmd.CommandType = CommandType.Text;

        //declare an SqlDataReader variable
        SqlDataReader dataReader;
        dataReader = cmd.ExecuteReader();

        if (dataReader.HasRows)
        {
            dataReader.Read();
            lblTotal.Text = dataReader.GetValue(0).ToString();
        }
        else
        {
            lblTotal.Text = "";
        }
        conn.Close();
    }

} //end of partial class shopcart

Open in new window

0
guru_samiCommented:
hmmm...looks fine....
might be stupid but...can you try creating a new page ....or did you already tried that?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sukotto100Author Commented:
I tried that, guru...I got it to work, by copying my professor's aspx and cs file and editing that. Weird...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.