1

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.

2
  • 'GridView' as in ASP.NET web forms or any other third party gridview? (I see you have tagged asp.net-mvc in your question) Commented Jun 8, 2012 at 2:22
  • Sorry for that, ASP.NET only. Commented Jun 8, 2012 at 3:11

1 Answer 1

2

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");
Sign up to request clarification or add additional context in comments.

6 Comments

textbox is always null. any idea?
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'
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
Gridview is dynamic and it will be generated as per the needs of the data source
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; } }
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.