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"
onitemcommand="DataList1_ItemCommand">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Bind("Name") %>'></asp:Label>
<asp:LinkButton ID="LinkButton1" runat="server" Text="Click Me"></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
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"
onitemcommand="DataList1_ItemCommand"
onitemdatabound="DataList1_ItemDataBound">
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