Solved

How do I use findcontrol with the asp.net 3.5 listview control?

Posted on 2009-04-02
2
677 Views
Last Modified: 2013-12-17
I have written a C# .Net web site using visual studio 2008. I have a listview control (ID = lvApplicants) where I need to access a linkbutton (ID = ITEditButton") located in my listview's ItemTemplate. I have tried the attached code but with no luck. Any pointers?
protected void lvApplicants_PreRender(object sender, EventArgs e)
    {
        //LinkButton btn_Edit = (LinkButton)lvApplicants.FindControl("ITEditButton");
 
        LinkButton btn_Edit = this.lvApplicants.FindControl("ITEditButton") as LinkButton;
 
        string editExpired = "return confirm('Edits cannot be made to this item as it has expired');";
        btn_Edit.Attributes.Add("OnClick", editExpired);
    }

Open in new window

0
Comment
Question by:Shepwedd
2 Comments
 
LVL 27

Expert Comment

by:nmarun
ID: 24053024
0
 

Accepted Solution

by:
Shepwedd earned 0 total points
ID: 24089270
I hope this helps someone else. My solution to this findcontrol issue was to use the below code in my listviews databound event:

LinkButton btn_Edit = (LinkButton)lvApplicants.Items[0].FindControl("ITEditButton");

In the above the "Items[0]" refers to the listview row. I had a itemtemplate and an alternatingitemtemplate so I had to reference both row 0 and 1 in my code behind to find these controls.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Studio hangs on running project 6 55
looking for an ASP.net report designer 4 40
Calculating percentage 2 27
c#, case, if 4 16
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question