Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2006

Tip: Looking for answers? Try searching our database.

FindControl to reference nested controls in gridview/listview

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Martin - 07 Feb 2006 16:37 GMT
Hi,

I have a very frustrating problem that I have researched for countless
hours to no avail. There are many posts asking very similar things,
however none usefull in my situation. I am using VS 2005 (ASP 2.0) and
VB .NET.

I have a page with a datalist, a gridview and then other data controls,
nested in that order. This all works great, and produces a nice looking
page, but I cannot for the life of me figure out how to reference
controls on the nested gridview and formviews. The HTML page is similar
to the below. What would be the correct syntaxt for referencing a
control on eg. FormView1 from Visual Basic code-behind? How does that
differ to a control on GridView2?

Can anyone point me in the right direction here? Perhaps a tutorial
that discusses these cases? I can post the actual code here, but I
thought the summary would be more meaningful.

<asp:datalist>
  <asp:GridView ID="GridView1">
      <asp:Boundfield>  </asp:BoundField>
      <asp:Boundfield>  </asp:BoundField>
      <asp:TemplateField>
          <asp:label ID="outerGridID">
           <asp:GridView  ID="GridView2">
          </asp:GridView>
          <asp:Repeater ID="Repeater1">
          </asp:Repeater>
          <asp:FormView ID="FormView1">
          </asp:FormView>
     </asp:TemplateField>
  </asp:GridView>
</asp:Datalist>

Many hopeful regards,

Martin
Phillip Williams - 07 Feb 2006 16:49 GMT
Hello Martin,

In this sample I have a DetailsView nested within a GridView which in turn
nested within a parent GridView.
http://www.webswapp.com/codesamples/aspnet20/nestedgridviews/

I access the controls within a GridView using the
GridView.SelectedRow.FindControl method.  As for the datalist you would
access the controls using the DataListItemEventArgs.Item.FindControl as in
this sample:
http://www.societopia.net/Samples/DataList_Hierarchy.aspx

Signature

HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com

> Hi,
>
[quoted text clipped - 34 lines]
>
> Martin
Scott Allen - 08 Feb 2006 15:26 GMT
>Can anyone point me in the right direction here? Perhaps a tutorial
>that discusses these cases? I can post the actual code here, but I
>thought the summary would be more meaningful.

Hi Martin:

I have a tutorial on using FindControl written here:

http://odetocode.com/Articles/116.aspx

Although the article doesn't specifically talk about FormViews and
GridViews, the concepts are the same. Most importantly, understanding
where an INamingContainer exists. I hope you find it helpful.

--
Scott
http://www.OdeToCode.com/blogs/scott/
Martin - 16 Feb 2006 15:52 GMT
Hi Phillip and Scott,

Many thanks for your help - I think there may be some basic concepts I
am having trouble with. I thought I might have to do a nested
FinControl, similar to:

DataList1.FindControl(GridView1.FindControl("GridView1"))

But I think CTYPE might be a clue to me.... I will dig into the
examples given and hopefully that will bring be closer to the answer.

Regards,

Martin

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.