Solved

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

Posted on 2009-04-02
2
678 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
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…

740 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