Click here to Skip to main content
11,584,612 members (68,321 online)
Rate this: bad
good
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
Edited 26-Jul-12 20:19pm
v2
Comments
_Amy at 27-Jul-12 2:27am
   
Where is your textbox in gridview? In Footer Template or item template or edit item template?
Kailash_Singh at 27-Jul-12 3:50am
   
It is in item template.....

1 solution

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

Solution 1

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:

//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
  Permalink  
v2
Comments
Kailash_Singh at 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 at 27-Jul-12 4:31am
   
Check my updated coding of finding the controls.
Kailash_Singh at 27-Jul-12 5:49am
   
Thanx Man....................
_Amy at 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
0 OriginalGriff 430
1 Sergey Alexandrovich Kryukov 367
2 Dave Kreskowiak 260
3 Richard Deeming 220
4 virusstorm 194
0 OriginalGriff 1,703
1 Sergey Alexandrovich Kryukov 1,267
2 Abhinav S 711
3 Dave Kreskowiak 687
4 Suvendu Shekhar Giri 568


Advertise | Privacy | Mobile
Web04 | 2.8.150707.1 | Last Updated 27 Jul 2012
Copyright © CodeProject, 1999-2015
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