Reputation: 2035
I have a repeater that has a linked button inside it. I want to get some data in linked button click event. how should I set my extra data and get them in click event? (consider that i want to concat some items in my property)
aspx code:
<asp:Repeater ID="rpSliderRest" runat="server">
<ItemTemplate>
<!-- ITEM-->
<div class="span2">
<div class="thumbnail product-item">
<img src='<%# Eval("PrintTemplate_URL").ToString().Replace("~", "../..") %>'>
</div>
<h6><%# Eval("PrintTemplate_Desc") %></h6>
<asp:LinkButton ID="lbtn1" runat="server" class="btn btn-large btn-block" OnClick="LinkButton1_Click"
Prperty='<%# string.Format("{0};{1}",Eval("PrintTemplate_URL").ToString(),Eval("PrintTemplate_ID").ToString()) %>'>Select »</asp:LinkButton>
</div>
<!-- ITEM-->
</ItemTemplate>
</asp:Repeater>
aspx.cs code:
protected void LinkButton1_Click(object sender, EventArgs e)
{
LinkButton lbtn = sender as LinkButton;
string MyProperty=??????????
}
Upvotes: 2
Views: 1412
Reputation: 8079
You can use the Attributes
collection.
For example:
protected void LinkButton1_Click(object sender, EventArgs e)
{
LinkButton lbtn = sender as LinkButton;
String MyProperty = lbtn.Attributes["PropertyName"];
}
Upvotes: 2
Reputation: 479
Personally I'd go down the route of using the link button commandArgument property - as that's what it's there for.
So:
<asp:LinkButton ID="lbtn1" runat="server" class="btn btn-large btn-block" OnClick="LinkButton1_Click"
CommandArgument='<%# string.Format("{0};{1}",Eval("PrintTemplate_URL").ToString(),Eval("PrintTemplate_ID").ToString()) %>'>Select »</asp:LinkButton>
Then
protected void LinkButton1_Click(object sender, EventArgs e)
{
LinkButton lbtn = sender as LinkButton;
string MyProperty= lbtn.CommandArgument;
}
Upvotes: 0