try myImagez.Items.Add(test);

On Thu, Dec 18, 2008 at 8:19 AM, Dixie Normous <[email protected]> wrote:

>
> I'm trying to populate a DataList object in an ASP .NET website app.
>
> Here is the DataList and its ObjectDataSource as defined in my .aspx
> page:
>
> <asp:DataList ID="dlThumbNails" runat="server"
> DataKeyField="ProductID" DataSourceID="ObjectDataSource1"
> EnableViewState="False">
> <ItemTemplate>
> <asp:Image runat="server" ImageURL='<%# ((Imagez)
> Container.DataItem).URL %>' />
> </ItemTemplate>
> </asp:DataList>
>
> <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
> OldValuesParameterFormatString="original... SelectMethod="GetImages"
> TypeName="WebApplication1._Default"> </asp:ObjectDataSource>
>
> Here is the GetImages method from my code-behind
>
> public void GetImages()
> {
>          int iCount;
>          string sURL;
>
>          List<string> URLs = new List<string>();
>
>          List<Imagez> myImagez = new List<Imagez>();
>
>          for (iCount = 0; iCount <= 20; iCount++)
>          {
>                    URLs.Add(@"<img src='http://mylink.com/image"; +
> iCount.ToString() + ".jpg'></img>";
>
>                    sURL = URLs[iCount];
>
>                    Imagez test = new Imagez();
>
>                    test.URL = sURL;
>
>                    myImagez.Add(test);
>          }
>
>          dlThumbNails.DataSource = myImagez;
>          dlThumbNails.DataBind();
>
> }
>
> When I debug the app, I get the following error:
>
>          Object reference not set to an instance of an object.
>          dlThumbNails.DataSource = myImagez;
>
> The DataList object in the debugger is NULL, although my object
> myImagez is populated and has data.
>
> What's wrong with my code?  Please help, thank you!!!
>

Reply via email to