Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have placed controls(TextBoxes) in the header template of the Datalist control. Can any body tell me how to find that control at run time(the code)?

(I actually want to access the values written in the text boxes by the user)

I even know how to do it in GridView
C#
String empnam =((TextBox)  (GridView1.FooterRow.FindControl("TextBox1"))).Text;


I want an equivalent one to it.
Posted
Updated 13-Aug-10 2:02am
v2

You can access it at the ItemDataBound event of datagrid. First item to bound is header item.

C#
if(if(e.Item.ItemType == ListItemType.Header))
{
    String empnam =((TextBox)(e.Item.Cells[0].Controls[1]).Text;
}
 
Share this answer
 
Comments
sachin_3333 14-Aug-10 3:05am    
Thank you very much
I would rather suggest to use FindControl() with a bit of defensive programming, in the ItemDataBound event of DataList:

C#
if (e.Item.ItemType == ListItemType.Header)
{
    TextBox txtEmp = e.Item.FindControl("TextBox1") as TextBox;
    if (txtEmp != null)
    {
        String empnam = txtEmp.Text;
    }
}
 
Share this answer
 
Comments
sachin_3333 14-Aug-10 3:05am    
Thank You very much

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