Click here to Skip to main content
15,903,783 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How i can find control in EmptyDataTemplate of GridView?
i test page.FindControl(),but it not worked
Posted

 
Share this answer
 
You wil not find the control because there is no rendered control
 
Share this answer
 
Hi...

I saw the solution 4 and I guessed interesting.

Well, in my case I created one WebUserControl for No data message called uscNoDataTemplate , and I needed set it up by public methods and properties, so...

DataView dv = ds.Tables[0].DeafultView;

grd.DataSource = dv;
grd.DataBind();

UserControls.uscNoDataTemplate uscNoDataTemplate1 = ((GridViewRow)grd.Controls[0].Controls[0]).Cells[0].FindControl("uscNoDataTemplate1") as UserControls.uscNoDataTemplate;

if(uscNoDataTemplate1 != null) //This is a simple and very important line to explain the concept: The control is null when your grid shows data because this control is not will be rendered
{
    uscNoDataTemplate1.MyNoDataMessage = "Unfortunately you do not have data!";
}


Hope it helps you...
 
Share this answer
 
TextBox txt = (TextBox)GridView1.Controls[0].Controls[0].FindControl("TextBox1");
 
Share this answer
 
Comments
antonache_radu@yahoo.com 29-Nov-12 1:35am    
Bingo.
Thank you very much.
Your question has the answer.

control in EmptyDataTemplate of GridView
Use FindControl in the GridView row.
 
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