Click here to Skip to main content
15,921,643 members
Please Sign up or sign in to vote.
4.20/5 (3 votes)
See more:
I have placed GridView1 inside a panel in .aspx file.Here is my code behind.
C#
foreach (GridViewRow gvrC in GridView1.Rows)
        {
            if (gvrC.Visible)
            {
                for (int x = 2; x < GridView1.Columns.Count; x++)
                {
                    foreach (Control cc in gvrC.Cells[x].Controls)
                    {
                        string str = ((TextBox)cc).Text;
                        //my code here. I want to display textbox value
                    }
                }
            }
        }

but it is not entering the 2nd foreach() loop.plz give me the solution.
Thank You.
Posted
Updated 4-Oct-13 0:29am
v2
Comments
Why in second loop, x = 2 ?
Shibasankar 4-Oct-13 7:20am    
becoz I have added text boxes from 3rd column(2nd position) in gridview...
Okay try like below...

foreach(GridViewRow gvrC in GridView1.Rows)
{
if (gvrC.Visible)
{
for(int i = 2; i < GridView1.Columns.Count, i++)
{
String str = row.Cells[i].Text;
}
}
}
Shibasankar 4-Oct-13 8:07am    
now this is entering to the loop,, but still some errors. now I am trying to rectify it.
Thank u Boss
Good... I am adding one answer. Please accept and up-vote.

Try the below codes. You don't have to worry about on which column you have put the text boxes. -

C#
foreach (GridViewRow gvrC in GridView1.Rows)
        {
                        string str = ((TextBox)gvrC .FindControl("txtCC")).Text;

                        //my code here. I want to display textbox value
        }
 
Share this answer
 
v2
Comments
What is cc here?
Madhu Nair 4-Oct-13 8:03am    
check the updated solution
Shibasankar 4-Oct-13 8:04am    
we have to define cc...
Madhu Nair 4-Oct-13 8:45am    
please check the updated solution. Replace"txtCC" in the code with your actual control id
Shibasankar 5-Oct-13 1:26am    
I am writing something in text box. But when I am trying to get that text box value, its giving  
Please help me correcting this one.
Okay try like below...
C#
foreach(GridViewRow gvrC in GridView1.Rows)
{
    if (gvrC.Visible)
    {
        for(int i = 2; i < GridView1.Columns.Count, i++)
        {
            String str = row.Cells[i].Text;
        }
    }
}
 
Share this answer
 
Comments
Shibasankar 4-Oct-13 8:15am    
Thank You...
Most Welcome. :)

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