Reputation: 41
I've created a ListView
with a dataset and I'm wondering how to reference to a LinkButton
within a ListView
, since I can't reach it in code behind.
The LinkButton
is within ItemTemplate
. I need to have it in code behind since I'm calling a if function on it. I've also tried OnClientClick on the linkbutton, but can't reach that either.
I'm sure I'm not the only one doing this, so is there another way to do this? more efficient?
Simplified code:
<asp:ListView ID="lstVDataBind" runat="server">
<LayoutTemplate>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</LayoutTemplate>
<ItemTemplate>
<asp:LinkButton ID="btndeleteClick" runat="server"><span>X</span></asp:LinkButton>
</ItemTemplate>
</asp:ListView>
Code behind:
btndeleteClick.Text = "for example"
But I can't reach it in code behind.
Upvotes: 0
Views: 654
Reputation: 300
Try this.
<asp:LinkButton Id="Linkbtn" CommandName="Linkbutn" runat="server"/>
then in code behind,
protected void lstVDataBind_ItemCommand(object sender, ListViewCommandEventArgs e)
{
(e.CommandName == "Linkbutn")
{
//do somthing
}
}
Upvotes: 1