Can't Populate FooterTemplate Label

W

Will Chamberlain

I have a footer template for adding items to a database. When 'Add'
button is pressed the footer is displayed with textboxes for inserting
data. There is 1 field that should not be tampered with so I am trying
to display the value in a label. I am using the following code:

<Asp:label id="lblDLID" text='<%# Container.DataItem("DLID") %>'
runat="server" />

In theory this should work like a charm but I am getting the following
error:

---------------
Object variable or With block variable not set.

Exception Details: System.NullReferenceException: Object variable or
With block variable not set.
---------------

I don't understand why I would get this error. The datagrid is bound so
I should be able to grab this value. Am I missing something here? Any
suggestions are welcomed.

- will
 
G

Guest

the following is a quote from MSDN for repeater control (but I think that
apply for datagrid as well):

"You cannot bind controls in the header, footer, and separator templates
using DataBinder.Eval expressions in HTML view. You must bind these controls
in the code."
 
W

Will Chamberlain

Thanks Alex. I tried a different method. Still no luck!

dim ds as new dataset
Dim objCommand as new oledbCommand(strSQL, objConn)
Dim myCommand as new OleDbDataAdapter(strSQL, objConn)

myCommand.Fill(ds, "DataTable")

lblID.text = ds.Tables("DataTable").Rows(0)("ID")

When I run the page nothing is displayed in the footer for this field.
I figured this way would work simply because the datagrid's datasource
is the same dataset. Since the dataset is already filled I should just
be able to grab the ID from the dataset right?

- will
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top