[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Gridview Within Repeater

Posted on 2009-02-17
9
Medium Priority
?
506 Views
Last Modified: 2012-05-06
Hi

I have a Gridview within a repeater bu am having problems referencing the Gridview in code behind using Page.FindControl("GridView1").

using the code below on page_load the page cant seem to find it (as in i always get the GridView not found msg)

Any ideas??

Thanks
If Page.FindControl("gvClientInfo") IsNot Nothing Then
			Response.Write("GridView Found")
		Else
			Response.Write("Grid View Not Found")
		End If

Open in new window

0
Comment
Question by:patelajk
  • 4
  • 2
  • 2
8 Comments
 
LVL 11

Expert Comment

by:jmwheeler
ID: 23659538
When your page loads pull of the view source from your browser and see what id's are assigned to the gridview.  Since the gridview is in the repeater it will have to modify the id so that each instance of the gridview has a unique id.  I can't test it now but it probably adds _1, _2, _3 etc for each instance of the gridview.
0
 
LVL 8

Accepted Solution

by:
SunnyDark earned 1000 total points
ID: 23659561
You should subscribe to the Repeater's ItemDataBound event and use the Item property of the RepeaterItemEventArgs to find the datagrid like this:

Sub R1_ItemDataBound(Sender As Object, e As RepeaterItemEventArgs)
e.Item.FindControl("gvClientInfo") .....
End Sub

0
 

Author Comment

by:patelajk
ID: 23659652
jmwheeler:

it adds it like:
ctl00_cphPageBody_Repeater1_ctl03_gvClientInfo and then
ctl00_cphPageBody_Repeater1_ctl04_gvClientInfo

any ideas on how to reference it
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 11

Expert Comment

by:jmwheeler
ID: 23659764
You could try Repeater1.FindControl("ctl00_gvClientInfo") but honestly SunnyDark's suggestion is better.
0
 

Author Comment

by:patelajk
ID: 23659779
tried

      Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs)
            'If Page.FindControl("gvClientInfo") IsNot Nothing Then
            '      Response.Write("GridView Found")
            'Else
            '      Response.Write("Grid View Not Found")
            'End If
      End Sub

but still didnt work and i get the later msg
0
 
LVL 11

Expert Comment

by:jmwheeler
ID: 23660264
did you try:

e.Item.FindControl("gvClientInfo")
instead of
Page.FindControl("gvClientInfo")
?
0
 
LVL 8

Expert Comment

by:SunnyDark
ID: 23663850
Look closely at my example and what jmwheeler wrote in his message, it should always work...
0
 
LVL 11

Expert Comment

by:jmwheeler
ID: 23664190
I was really just reiteraing what SunnyDark posted.  You probably should have accepted SunnyDark's posting or used a points split.  Thanks though.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Integration Management Part 2
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

825 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