Hi,
I am on page 494,working on try it out exercise. When i request page GenreLinq.aspx in browser it gives me an error showing "object reference not set to an instance of an object". Below is the code from mark up of the page and code behind of the page
Code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Id" DataSourceID="LinqDataSource1"
onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False"
ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="SortOrder" HeaderText="SortOrder"
SortExpression="SortOrder" />
</Columns>
</asp:GridView>
and in the code behind of the page
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Management_GenreLinq : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
switch (e.Row.RowType)
{
case DataControlRowType.DataRow:
Genre myGenre = (Genre)e.Row.DataItem;
LinkButton deleteButton = (LinkButton)e.Row.FindControl("LinqButton1");
deleteButton.Enabled = myGenre.Reviews.Count == 0;
break;
}
}
}
i am having a following error
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 19: Genre myGenre = (Genre)e.Row.DataItem;
Line 20: LinkButton deleteButton = (LinkButton)e.Row.FindControl("LinqButton1");
Line 21: deleteButton.Enabled = myGenre.Reviews.Count == 0;
Line 22: break;
Line 23: }
Source File: c:\BegASPNET\Site\Management\GenreLinq.aspx.cs Line: 21
Can anyone figure out why this unhandled exception occured?
pls help
Arya