Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
Send secure, cloud-based, encrypted alerts and maintain HIPAA compliant messaging. Integrates priority & secure messaging into one application. Ensures IT, emergency respondents and healthcare professionals that their critical messages are never mis…

911 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

23 Experts available now in Live!

Get 1:1 Help Now