Click here to Skip to main content
12,297,822 members (55,330 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# C#4.0
I have a gridveiw in which there is panal inside itemtemplate and the panal contains other server control.

i want to use this panle in and server controls and change their text and other values using C# but i can't find the controls in side the panal.
Posted 26-Sep-12 18:37pm
Comments
Kenneth Haugland 27-Sep-12 3:51am
   
Winforms or WPF?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try YourPanelName.FindControl()

Look on similar threads:
Finding all controls in an ASP.NET Panel[^]
How do I find a control I placed inside a panel?[^]

..and more threads here[^]
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

For finding controls inside the Panel you may use the "Controls" property. See this code:
foreach(Control ctrl in panel1.Controls)
{
  ctrl.Text = "Hello";
}
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

As the panel is inside the item template, it will be repeated for each row in grid view.

So first you have to take the row in which you want to change control's text.

e.g. GridViewRow gr = Gridview1.Rows[0];//taking the first row

Then you can find the panel as follows :

Panel tempPanel = (Panel)gr.FindControl("PanelID");

And then you may find the textbox inside the panel using

TextBox txt = (TextBox)tempPanel.FindControl("TextBoxID");

Or you may find this textbox directly inside the grid view row (if the textbox id is unique in the page) as follows:

TextBox txt = (TextBox)gr.FindControl("TextBoxID");


Now you can change the text of the control as : txt.Text = "New Value";


Hope this helps you !!
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160525.2 | Last Updated 27 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100