Click here to Skip to main content
12,897,914 members (79,947 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
I want to access Text box value inside grid view and that grid view is in tabpannel.

Following is my code, where I got tab panel name but not able to access grid view and text box.

string str = null;
        AjaxControlToolkit.TabContainer container = (AjaxControlToolkit.TabContainer)TabContainer1;
        foreach (object obj in container.Tabs)
            if (obj is AjaxControlToolkit.TabPanel)
                AjaxControlToolkit.TabPanel tabPanel = (AjaxControlToolkit.TabPanel)obj;
                //Code for tab panel header text
                str = tabPanel.HeaderText.Trim();
                foreach (object ctrl in tabPanel.Controls)
                    if (ctrl is Control)
                        Control c = (Control)ctrl;
                        foreach (object innerCtrl in c.Controls)
                            if (innerCtrl is System.Web.UI.WebControls.GridView)
                             //control didn't enter this block...   
                             int k = 0;                                

please help me thanx in advanced....
Posted 26-Jul-12 18:57pm
Updated 26-Jul-12 20:19pm
_Amy 27-Jul-12 2:27am
Where is your textbox in gridview? In Footer Template or item template or edit item template?
Kailash_Singh 27-Jul-12 3:50am
It is in item template.....

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

First of all let me tell you one thing that your can directly access your gridview by it's id. No matters when it is in tab panel. All the controls of tab panel you can access directly by calling it using it's id like GridView1.

Now the problem is where is your textbox inside gridview.
If your textbox is in item template then you can access it by using this:

//Updated Looping through the controls of tabcontainer
foreach(Control s in tabContainer1.Controls) 
    // If control is gridview
    if (s is GridView) { 
        //Looping through gridview
        foreach (GridViewRow dr in gridview.Rows)
            //Finding the Textboxes
            TextBox txt=(TextBox)dr.FindControl("YourTextBoxID");
            // Do your work with txt..

Refer this[^] for more information.

Kailash_Singh 27-Jul-12 3:49am
Thanx Amit ...
Its suitable when you have one or two tab grid view
but I have more than 20 tabpanel and each panel have its own grid view....
that's why I am using for each loop in tab container....but couldn't find grid view.....
_Amy 27-Jul-12 4:31am
Check my updated coding of finding the controls.
Kailash_Singh 27-Jul-12 5:49am
Thanx Man....................
_Amy 27-Jul-12 5:50am
Welcome Kailash.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 27 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100