Hello everybody! :)
I hope somebody can give me some advice on how to solve this:
I have a very simple DataList defined like this:

<asp:datalist id="DataList1" runat="server" Width="90%" 
HorizontalAlign="Center">
   <HeaderTemplate>
      <asp:Button ID="Button1" Runat="server" Text="New 
Entry"></asp:Button>
   </HeaderTemplate>

   <ItemTemplate>
      <Table width="100%" cellspacing="5">
         <tr>
         <td>Name:</td>
         <td><%# DataBinder.Eval(Container.DataItem, "Name") %></td>
         </tr>
         <tr>
         <td>Email:</td>
         <td><%# DataBinder.Eval(Container.DataItem, "Email") %></td>
         </tr>
         <tr>
         <td>Website:</td>
         <td><%# DataBinder.Eval(Container.DataItem, "Website")%></td>
         </tr>
      </Table>
   </ItemTemplate>
</asp:datalist>


Now the problem is with the "Button1" defined in the HeaderTemplate, 
for some reason it does not seem to be recognized by the code behind 
class:

....
protected System.Web.UI.WebControls.Button Button1;
....
private void InitializeComponent()
{
   this.Button1.Click += new System.EventHandler(this.Button1_Click);
   this.Load += new System.EventHandler(this.Page_Load);
}
....
private void Button1_Click(object sender, System.EventArgs e)
{
   Console.WriteLine("Button1 Clicked!");
}

The first line in the InitializeComponent method gives me this 
runtime error:
"Object reference not set to an instance of an object"

Now if in the aspx page I take Button1 outside the DataList is works 
fine ... What am I doing wrong in the DataList then?? :(


Thank you very much for your help :)


Victor.







------------------------ Yahoo! Groups Sponsor --------------------~--> 
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to