Click here to Skip to main content
15,909,835 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I want to know how to get the value of the label box which is specified inside the datalist.

Please reply to me.
Posted
Updated 4-Mar-11 0:29am
v2
Comments
Dalek Dave 4-Mar-11 6:29am    
Edited for Grammar and Spelling.

If you are using in the datalist events then

Label Label1 = e.Item.FindControl("Label1") as Label;
string lblValue=Label1.Text;


Other than datalist events
C#
foreach (DataListItem dli in DataList1.Items)
            {
               Label Label1 = e.Item.FindControl("Label1") as Label;
               string lblValue=Label1.Text;
}
 
Share this answer
 
Comments
Dalek Dave 4-Mar-11 6:29am    
Good Answer
Using FindControl method?

Try:
VB
//VB.NET
Dim lblId As Label = CType(Item.FindControl("lblId"),Label)

C#
// C#
Label lblId = new Label();
lblId = (Item.FindControl("lblId")) as Label;
 
Share this answer
 
when i used this i get the error in application file like identifier expected
 
Share this answer
 
Findcontrol doesnot exist will occur
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900