Problem with label inside a datalist

  • Thread starter Thread starter Bruno Piovan
  • Start date Start date
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!
 
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.
 
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
 
Back
Top