Click here to Skip to main content
11,505,486 members (58,481 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#3.0
how to get the text on a link button which is in a datalist.
Posted 29-Aug-10 19:26pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You didn't mention where you need to get the text of the LinkButton. In Code behind? Or, in JavaScirpt.

Assuming that you need the text in CodeBehind, you can get the text as follows:

Add an ItemCommand event in the DataList control

<asp:DataList ID="DataList1" runat="server"
           <asp:Label ID="Label1" runat="server" Text='<%#Bind("Name") %>'></asp:Label>
           <asp:LinkButton ID="LinkButton1" runat="server" Text="Click Me"></asp:LinkButton>

And, get the Text of the LinkButton in the ItemCommand event handler as follows:

protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
       LinkButton linkButton = e.CommandSource as LinkButton;
       string commandText = linkButton.Text;

Or, if you need to get the LinkButton text at page load (Data Bound), you can get it as follows:

Add an ItemDataBound event handler to the DataList

<asp:DataList ID="DataList1" runat="server"

Get the LinkButton Text in the event handler method:

protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
       if (e.Item.ItemType == ListItemType.Item)
           LinkButton linkButton = e.Item.FindControl("LinkButton1") as LinkButton;
           string commandText = linkButton.Text;

Please let me know if you need to get the text using JavaScript
srujanac# at 30-Aug-10 2:01am
thanks i think this would help me i'll try and let you know
Dorababu743 at 30-Aug-10 2:14am
Reason for my vote of 5
Nice way of explanation
Al-Farooque Shubho at 30-Aug-10 2:34am
rakeshjena at 17-Jan-14 14:05pm
why you have chosen bind here why not eval
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can use FindControl to find that particular linkbutton on the on- click function.Then assign the text value of linkbutton to the textbox you need to assign.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 512
1 F-ES Sitecore 380
2 Richard Deeming 270
3 CHill60 245
4 Richard MacCutchan 230
0 Sergey Alexandrovich Kryukov 1,067
1 Maciej Los 575
2 Peter Leow 540
3 F-ES Sitecore 525
4 DamithSL 470

Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 30 Aug 2010
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100