Click here to Skip to main content
13,043,898 members (64,877 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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# 30-Aug-10 2:01am
thanks i think this would help me i'll try and let you know
Dorababu743 30-Aug-10 2:14am
Reason for my vote of 5
Nice way of explanation
Al-Farooque Shubho 30-Aug-10 2:34am
rakeshjena 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 30 Aug 2010
Copyright © CodeProject, 1999-2017
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