Groups | Blog | Home
all groups > vb.net > june 2007 >

vb.net : Object reference not set to an instance of an object


Ben
6/26/2007 8:23:03 PM
Hi,

I want to access in code-behind a label within the ItemTemplate of a
Formview.

<asp:FormView ID="FormView1" runat="server" DataKeyNames="id"
DataSourceID="SqlDataSource1" >
<ItemTemplate>
<asp:Label ID="nameLabel" runat="server" Text='<%# Bind("name")
%>'></asp:Label>

code-behind:
Dim name As String = CType(FormView1.FindControl("nameLabel"), Label).Text


I get the error: "Object reference not set to an instance of an object"

Could somebody tell me what's wrong in my code?
Thanks
Ben



pintu
6/27/2007 2:54:07 AM

[quoted text, click to view]

The problem is with the viewstate of the formview control. Just enable
the view state of the control and make sure u are not populating it in
button's click; access it.
Hope this will solve your problem.
AddThis Social Bookmark Button