Ty this way:
Following binds the ItemName to the
CommandArgument
of the
LinkButton
.
<asp:LinkButton ID="LinkButton1" runat="server" Text="Add to cart"
OnClick="LinkButton1_Click" CommandArgument='<%# Eval("ItemName") %>' />
You can then retrieve it like this in the code behind:
protected void LinkButton1_Click(object sender, EventArgs e)
{
LinkButton myButton = sender as LinkButton;
if (myButton != null)
{
string title = myButton.CommandArgument;
}
}
The sender holds a reference to the
LinkButton
that triggered the event handler.
You can cast the object into a
LinkButton
and then retrieve its
CommandArgument
and cast that into string.