Object reference not set to an instance of an object.

C

Chris Fink

Hello,

I have a user control that contains a datalist and within that a asp label,
as follows:

<asp:DataList ID="dlHomeDetail_Starters" Runat="server" CellPadding="1"
CellSpacing="1" Width="100%" RepeatDirection="Vertical" RepeatColumns="1">
<HeaderTemplate>
<tr class=mainhead vAlign=center>
<td class=away colSpan=5><asp:Label ID="lblGroupName"
Runat="server"></asp:Label></td>
</tr>
<tr class=bg1 align=middle>

In my code behind, in the page load event I am receiving this error "Object
reference not set to an instance of an object" on this line
lblGroupName.Text = "Test".

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

lblGroupName.Text = "Test"

dlHomeDetail_Starters.DataSource =
oFFLLeague.getPlayerStats_TeamSummary(Session("FFLLeagueID"),
Request.Params("week"),
oFFLLeague.getHomeTeamIDFromGameID(Request.Params("week"),
Request.Params("gid")), "Starters")
dlHomeDetail_Starters.DataBind()

End Sub

Is my problem due to the sequence of events in the webform page load and
that the label is not yet available? I always find understanding the order
of events confusing when using a user control.

Any help is appreciated,
Thanks Chris
 
T

Terry Orzechowski

Usually when you get the error it is because of a type
mismatch. But things that I see in your code are that you
seem to be calling databind without filling your dataset
with a data adapter?
 
D

David Waz...

Your data-bound control results in multiple label
controls, not just one.

you need to go through the rows of the resulting control
to find the label you want, or use findControl or any
other number of ways to navigate the control structure.
 

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,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top