I am going through a great book learning C# 5.0 and ASP.Net and came across data binding with controls. I have gone through the necessary steps to bind the data but I am receiving a confusing error message as the code below states.
Show.cs //Class for the show properties
namespace BindingExample
{
public class Show
{
public int ID {get; set;}
public String ShowName {get; set;}
}
}
LabelText.aspx.cs //user control code behind
namespace BindingExample
{
public partial class Label LabelText: System.Web.UI.Page
{
protected void load_page(object sender, Event args)
{
Show show = new Show
{
ID = 1,
ShowName = "C# is the Best"
};
//binding
Page.Binding();
}
}
LabelText.aspx //user control markup where the problem occurs.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LabelText.aspx.cs" Inherits="BindingExample1.LabelText" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="<%# show.ShowName%>"></asp:Label>
</div>
</form>
</body>
</html>
This is where the problem occurs, intellisense is telling me that show.ShowName is not in the current context, I don't know why as first it is exactly what the book presented and also why it would not be since Show.cs class is in the same folder? Any help solving this will be really appreciated. Thanks