p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

aspx thread: ImageButton Inside a HeaderTemplate possible?

Message #1 by "Russell Gordon" <ragordon@e...> on Tue, 27 Feb 2001 13:12:33

Right now, I am having a problem trying to access an Image Button's 

Imageurl property from CodeBehind.  The Image Button is inside the header 

template of a datagrid and I want to programmatically (C#) change the 

ImageUrl property of the Image Button.  I have the following in my aspx 

file (This is for one of the columns in the data grid):

<asp:TemplateColumn headerstyle-horizontalalign="Center" >

     <template name="HeaderTemplate">

         <asp:ImageButton ID="SortBySongName" runat="server"

             AlternateText="Sort By Track Name"





     <template name="ItemTemplate" >

         <b><%# DataBinder.Eval(Container.DataItem,"SongName","{0}") %></b>



Then I have a declared Image button above the page_load in the codebehind 

file as follows:

protected System.Web.UI.WebControls.ImageButton SortBySongName;

When I try to programmatically (in CodeBehind) assign a url string to the

Image buttons ImageUrl property like below:

SortBySongName.ImageUrl = "";

I get the famous "Attempted to dereference a null object reference."

Any ideas?

Thanks in Advance,

Russell Gordon

  Return to Index