Assign Text to Footer Label

  • Thread starter Will Chamberlain
  • Start date
W

Will Chamberlain

I'm trying to populate a label that is located in the Footer Template of
my DataGrid. I want this to be displayed in a label instead of a
textbox when the user wants to add a new record because I don't want
them to have mess with this field.

-----
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? Any suggestions?
 
G

Guest

this is fine, more then likely though you are setting the label text from
outside the proper event. Is the DS already populated? if so you will have to
dig into the DG and grab the footer to get at the label... the label probably
isn't exposed to the page directly.
 
T

Trevor Benedict R

Check out the ItemDataBound Event.

if e.Item.ItemType = ListItemType.Footer Then
'Declare strValue & store the value from
'ds.Tables("DataTable").Rows(0)("ID") into this variable
ctype(e.Item.FindControl(""), Label).Text = strValue
'ds.Tables("DataTable").Rows(0)("ID")
End If

Basically you need to understand the lifetime of each control and then you
will understand as to where you could sneak the code. Hope that helps.

Regards,

Trevor Benedict R
MCSD
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top