Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys

I have a datalist control and in its item template I have a label and an imagebutton the lable is binded to column in database

the scenario is that the label is the title for a book and the details is in another page, I want that when I click the image button to redirect to the other page with the title in the link

how to get the text on the specific label in the datalist item template?

thanks in advance
:-)
Posted

For Example the image button CommandName "Item".

Click on ItemCommand property of DataList to create a protected void. Fill the protected void as follows.
C#
if (e.CommandName == "Item")
{
Label label1 = (Label)DataList1.Items[e.Item.ItemIndex].FindControl("Label1");
string labelValue= label1.Text;
}


I hope the above information will be helpful. If you have more concerns, please let me know.
 
Share this answer
 
Comments
a1mimo 28-Apr-11 3:17am    
Thank you for your answer but actually this solution for some reason doesnt work for me
it always return null when I debug as if it cant find "Label1" at all
thanks again :-)
a1mimo 28-Apr-11 3:20am    
here is something that I may add it might cause the problem "Label1" Text is binded to database, will this make any difference?
a1mimo 28-Apr-11 10:09am    
Thank You I got it now.
Monjurul Habib 28-Apr-11 12:01pm    
great.
nitish nalan 30-Apr-11 12:11pm    
a1mimo can u xplain me in brief plzzz
hey can u xplain this in brief, evn i m facing the same problm, it is takin null value
 
Share this answer
 
Comments
a1mimo 22-Oct-12 12:41pm    
nitish nalan I am sorry for so late answer I just didn't log in for a very long while but I actually remember what was the problem it was just a hang up and the previous solution worked best for me all I needed to do is to delete the label and create it again sorry for late one more time but after all better late than never :-)

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