Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

726 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