Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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 at 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
0 OriginalGriff 223
1 Sergey Alexandrovich Kryukov 181
2 nv3 50
3 Mehdi Gholam 45
4 VJ Reddy 45
0 Sergey Alexandrovich Kryukov 6,696
1 OriginalGriff 6,149
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


Advertise | Privacy | Mobile
Web04 | 2.8.140823.1 | Last Updated 27 Sep 2012
Copyright © CodeProject, 1999-2014
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