Problem with label inside a datalist

B

Bruno Piovan

Hi,
I have a datalist, this datalist has a label for each item called lblId,
this label hold the ID of each item. I need to write a procedure that will
use the value of the label of each item, I'm using the FindControl method
but the return value is aways "".

How do I get the text of the labels??


Thanks!
 
J

Jos

Bruno said:
Hi,
I have a datalist, this datalist has a label for each item called
lblId, this label hold the ID of each item. I need to write a
procedure that will use the value of the label of each item, I'm
using the FindControl method but the return value is aways "".

How do I get the text of the labels??

Did you use FindControl properly, like this (I use VB.NET):

Dim lblId As Label = CType(Item.FindControl("lblId"),Label)

A better way to find the IDs is to set the DataKeyField property
of the datalist to the name of the database field (probably "ID"),
and use DataList1.DataKeys(Item.ItemIndex) to get the value
of the ID.
 
B

Bruno Piovan

Yes,
I was using findcontrol that way.

but DataKeys worked great, I don't need to have the ID shwon.

working great now,
I love you man.

thanks
 

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

Similar Threads


Top