Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Updated 14-Dec-19 3:26am
Comments
Kenneth Haugland 27-Sep-12 3:51am    
Winforms or WPF?

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[^]
 
Share this answer
 
For finding controls inside the Panel you may use the "Controls" property. See this code:
C#
foreach(Control ctrl in panel1.Controls)
{
  ctrl.Text = "Hello";
}
 
Share this answer
 
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 !!
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900