473,804 Members | 3,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LinkButton in Repeater control

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:Repeater 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 >
...


Aug 21 '08 #1
5 13942
Peter Larsen [CPH] wrote:
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:Repeater 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 >
...

You want to handle the ItemDataBound event for dataRepeater.

In the event handler check e.Item.ItemType and when it is Header you can
do a e.Item.FindCont rol("testLink") to get a reference to the
LinkButton. From there change what you need.

Hope this helps
LS
Aug 21 '08 #2
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 >
...


Aug 22 '08 #3
Hi Steven,

Thank you for the solution.
It seems to be what i need.

BR
Peter
"Steven Cheng [MSFT]" <st*****@online .microsoft.comw rote in message
news:Yg******** ******@TK2MSFTN GHUB02.phx.gbl. ..
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

Aug 22 '08 #4
Hei Lloyd,

Thank you for your answer to my question.

BR
Peter.

"Lloyd Sheen" <a@b.cwrote in message
news:%2******** **********@TK2M SFTNGP05.phx.gb l...
>
You want to handle the ItemDataBound event for dataRepeater.

In the event handler check e.Item.ItemType and when it is Header you can
do a e.Item.FindCont rol("testLink") to get a reference to the LinkButton.
From there change what you need.

Hope this helps
LS

Aug 22 '08 #5
You're welcome Peter,

I'm glad that it 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.

--------------------
>From: "Peter Larsen [CPH]" <Pe*********@co mmunity.nospam>
References: <uZ************ **@TK2MSFTNGP04 .phx.gbl>
<Yg************ **@TK2MSFTNGHUB 02.phx.gbl>
>Subject: Re: LinkButton in Repeater control
Date: Fri, 22 Aug 2008 09:37:46 +0200
>
Hi Steven,

Thank you for the solution.
It seems to be what i need.

BR
Peter
"Steven Cheng [MSFT]" <st*****@online .microsoft.comw rote in message
news:Yg******* *******@TK2MSFT NGHUB02.phx.gbl ...
>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:

============as px =============== ==
<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>

============== code 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,
RepeaterItemEv entArgs 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


Aug 25 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3810
by: Peter Kirk | last post by:
Hi are there any "gotchas" with using an asp:repeater that means that the "onclick" method of a LinkButton created in the repaeter does not fire? I at least cannot get it to work. I have a webpage where the user can enter some search criteria (via dropdowns and textboxes) and then perform a search and have results presented. The results list includes linkbuttons which the user can click on to obtain more detailed results.
0
1999
by: Pat Sagaser via .NET 247 | last post by:
I'm trying to add LinkButtons to a Repeater control using adynamic template. The docs state that you should be able tobubble the click event to the containing Repeater. There areplenty of examples in the documentation for doing this using an<ItemTemplate> tag, but I haven't found any indication for howyou would do this in a dynamic template (implementing theITemplate interface). I'm adding the LInkButton in the TemplateDataBinding...
1
5254
by: Sandy | last post by:
I have a repeater which shows Group names. (Skip this part if you want rather irrelevant) The groups are ordered and formatted: Parent ---Child ------Grand Child (okay start reading again please)
5
3301
by: George Durzi | last post by:
I currently have an href inside of an asp:repeater <a href='<%# String.Concat("PDFReader.aspx?id=", DataBinder.Eval(Container.DataItem, "ProductUniqueId")) %>' target="_blank">View</a> Clicking View will open a new browser and load PDFReader.aspx My client would like me to hide the address bar and toolbar on this new
5
5452
by: UnknownServices | last post by:
I've added a LinkButton to a repeater control and I set the link button as follows: <asp:LinkButton ID="DLLinkButton" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "DownloadID")%>' Runat=server CommandName="DLCount" >Download Now!</asp:LinkButton> When I click this button it dosen't do anything instead of calling the function I created.
1
2172
by: smash2004 | last post by:
I have VS 2005 CTP. I created a page with one repeater. Inside i put a linkbutton. Usually when i put linkbutton on a page I doubleclick it in designview and event gets created in codebehind file. Now i can't click on anything because my linkbutton is not visible in the designer. So i moved my linkbutton outside the repeater and doubleclicked it and code gets created. With code created I moved my linkbutton again inside
2
10783
by: msnews.microsoft.com | last post by:
I want to read information out of a database at runtime (names of files available to download) and create a list of linkbuttons that the user can click on to download the file(s). How can I accomplish this. I've got this far: In the html: .... table>
13
10186
by: rn5a | last post by:
In a shopping cart app, suppose a user has placed 5 orders, I want to show him 5 LinkButtons (one for each order) so that when he clicks the first LinkButton, he would be shown the details of his first order. Likewise if he clicks the second LinkButton, he will be shown the details of the second order he had placed. The Text of the LinkButtons will be 1 2 3 etc. So this user would see 1 2 3 4 5 as the LinkButtons. The problem is...
0
1325
by: JSanford9482 | last post by:
Hi All, I have a Repeater that contains a LinkButton as one of the items in the ItemTemplate. I have the OnCommand (method is called "messageActions") and CommandName ("view") properties set, as well as a CommandArgument for the LinkButton to fire off when clicked. For some reason, when I try to set the CommandEventHandler for the LinkButton: this.messageSubject.Command += new CommandEventHandler(messageActions);
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5515
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.