Using For Each to update controls in repeater

J

Jason James

Guys,

I have a webform that uses a datalist control to display
a series of thumbnail images. Each image is is also associated
with two dropdown lists. One contains the quantity
of images required and the other contains the size
of the image that is requried. The qty dropdown list
is populated as follows:

dlQty = CType(e.Item.FindControl("dlQty"), DropDownList)
dlQty.Items.Clear()
dlQty.SelectedIndex = 0
dlQty.Items.Add("0")
dlQty.Items.Add("1")
dlQty.Items.Add("2")
dlQty.Items.Add("3")
dlQty.Items.Add("4")
dlQty.Items.Add("5")

where dlQty is defined as

Protected WithEvents dlQty As DropDownList

and the size dtopdown list is populated as follows using an
array of strings that contain the sizes:

Try
dlSize1 = CType(e.Item.FindControl("dlSize"),
DropDownList)
If Not IsNothing(dlSize1) Then
Dim rp() As String = CType(Session("rep"),
String())
Dim r As String
For Each r In rp
dlSize1.Items.Add(r)
Next
dlSize1.SelectedIndex = 0
End If
Catch ex As Exception
Label1.Text = ex.Message.ToString
End Try

where dlSize1 is defined as

Protected WithEvents dlSize1 As DropDownList

The contents of the array are obtained from a database during the
page preLoad event.

These sections of code are executed in the DataList1.ItemCreated
handler routine.

This code works without error when run on my local development
machine and also on our intranet server. It also runw without
any problems on one of the web hosting servers that I have an
account. My client has hosting at a different ISP, that assures
me that they are capable of supporting ASP.NET V2.

However, when I run this routine on their server it get an

Object reference not set to an instance of an object

exception raised when trying to populate the dlSize dropdowns.

Other code is also executed in the ItemDataDBound event of
the datalist control.

Anyone got any suggestions why most serves cope with this
code and yet another one fails to recognise the controls?

Many thanks,

Jason.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,829
Latest member
PIXThurman

Latest Threads

Top