Hi Peter,
As other member suggested, you can register the "ItemCreate d" event of
Repeater control and then use "FindContro l" to locate the linkbutton. Here
is a complete example (with aspx and codebehind) which demonstrate this:
============asp x =============== ==
<form id="form1" runat="server">
<div>
<asp:Repeater id="dataRepeate r" runat="server"
onitemcreated=" dataRepeater_It emCreated">
<HeaderTemplate >
Header data
<table class="repeat_t able">
<tr id="rowHeadLine ">
<td id="fieldHeadLi ne">
<asp:LinkButt on
ID="testLink"
runat="server"
Text="hit me">
</asp:LinkButton>
</td>
</tr>
</HeaderTemplate>
<ItemTemplate >
<tr>
<td><hr />item</td>
</tr>
</ItemTemplate>
<FooterTemplate >
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
==============c ode behind========= ====
public partial class RepeaterPage : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{
string[] items = new string[] { "aaa", "bbb", "ccc", "ddd" };
dataRepeater.Da taSource = items;
dataRepeater.Da taBind();
}
}
protected void dataRepeater_It emCreated(objec t sender,
RepeaterItemEve ntArgs e)
{
if (e.Item.ItemTyp e == ListItemType.He ader)
{
LinkButton lbtn = e.Item.FindCont rol("testLink") as LinkButton;
if (lbtn != null)
{
lbtn.CommandNam e = "Display"; lbtn.CommandArg ument =
"argument";
lbtn.Click += delegate
{
Response.Write( "<br/>LinkButton clicked");
};
}
}
}
}
=============== ===========
Hope this helps.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/...tance&ln=en-us.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Peter Larsen [CPH]" <Pe*********@co mmunity.nospam>
Subject: LinkButton in Repeater control
Date: Thu, 21 Aug 2008 23:11:03 +0200
>Hi,
The following sample shows a LinkButton in the HeaderTemplate of a
Repeater
>control.
The problem is that i'm not able to access the linkbutton in code (in the
cs
>file) as long as the linkbutton stays in the
repeater control - see the following line:
testLink.Comman dArgument = "just testing"; or testLink.Text = "Some
new
>text";
How do i dynamically change the properties of the LinkButton in runtime ??
Thank you in advance.
BR
Peter
Sample code:
<asp:Repeate r id="dataRepeate r" runat="server">
<HeaderTemplate >
Header data
<table class="repeat_t able">
<tr id="rowHeadLine ">
<td id="fieldHeadLi ne">
<asp:LinkButt on
ID="testLink"
runat="server"
OnClick="testfu nc"
Text="hit me">
</asp:LinkButton>
</td>
</tr>
</HeaderTemplate>
<ItemTemplate >
...