Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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
Updated 26-Jul-12 20:19pm
v2
Comments
_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

Hi,
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:

C#
//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.


--Amit
 
Share this answer
 
v2
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900