We help IT Professionals succeed at work.

Gridview Within Repeater

patelajk asked
Medium Priority
Last Modified: 2012-05-06

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??

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

Open in new window

Watch Question

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.
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts



it adds it like:
ctl00_cphPageBody_Repeater1_ctl03_gvClientInfo and then

any ideas on how to reference it
You could try Repeater1.FindControl("ctl00_gvClientInfo") but honestly SunnyDark's suggestion is better.



      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")
            '      Response.Write("Grid View Not Found")
            'End If
      End Sub

but still didnt work and i get the later msg
did you try:

instead of
Look closely at my example and what jmwheeler wrote in his message, it should always work...
I was really just reiteraing what SunnyDark posted.  You probably should have accepted SunnyDark's posting or used a points split.  Thanks though.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.