Solved

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

Posted on 2009-04-02
2
674 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now