I have Gridview and the headers are having textboxs and labels, I have a search button out side of the gridview and when a user clicks on search I need to filter gridview's data by respective column's texbox values.
-
'GridView' as in ASP.NET web forms or any other third party gridview? (I see you have tagged asp.net-mvc in your question)Prashanth Thurairatnam– Prashanth Thurairatnam2012-06-08 02:22:36 +00:00Commented Jun 8, 2012 at 2:22
-
Sorry for that, ASP.NET only.vml19– vml192012-06-08 03:11:14 +00:00Commented Jun 8, 2012 at 3:11
Add a comment
|
1 Answer
Try this
TextBox textBox = (TextBox)gridView1.HeaderRow.FindControl("contorlId");
to specifically search within a column identify the cell by the index
TextBox textBox = (TextBox)gridView1.HeaderRow.Cells[0].FindControl("contorlId");
6 Comments
vml19
textbox is always null. any idea?
vml19
Actually I am creating Textbox dynamically and text box Id in runtime is 'ctl00_sys_ABC_gridView1_ctl01_txtXYZ' , I am using update panel called 'ABC'
Prashanth Thurairatnam
are you autogenerating the gridview? why not create the columns for the gridview so that in the designer you can place your textbox inside asp:TemplateField/HeaderTemplate
vml19
Gridview is dynamic and it will be generated as per the needs of the data source
Prashanth Thurairatnam
If your controls are dynamic make sure you don't lose them on postback. If you have few controls in your header column, probably you can identify the control by type and read the value
foreach(Control c in gridView1.HeaderRow.Cells[0].Controls) { if (c is TextBox) { string value = ((TextBox)c).Text; } } |