Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 16th, 2010, 05:50 AM
Authorized User
 
Join Date: Dec 2009
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 14:Page 494 try it out

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
 
Old March 16th, 2010, 09:55 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Arya,

Take a look at the names of your LinkButton controls. It's LinkButton1 with a K in the Mark Up but you''re using LinqButton1 with a Q in the code...

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 18th, 2010, 10:34 AM
Authorized User
 
Join Date: Dec 2009
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
Default

oh!!! I really used to make this kind of mistakes....
thanks a lot Imar,

regards
Arya





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 14 (Page 483) CSS Declaration jsymons BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 11 September 18th, 2009 07:14 AM
Chapter 14 page 491 Will BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 4 April 25th, 2009 04:52 AM
Chapter 14 - Warnings on page 484 havardoj BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 February 22nd, 2009 04:31 PM
Chapter 14 page 580 Problems with example john_reeve41 BOOK: Beginning ASP 3.0 3 February 4th, 2004 10:21 AM
Chapter 14 Page 780-781 JonR BOOK: Professional C#, 2nd and 3rd Editions 0 August 11th, 2003 08:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.