Click here to Skip to main content
15,913,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I need to read the allcolumns of a row in a gridview. I use the following code to do so.

C#
foreach (GridViewRow row in gridvw.Rows)
          {
              DataRow dr;
              dr = table.NewRow();

              //string str = gridvw.Rows(0).Cells(0).Text;
              for (int i =0; i < row.Cells.Count-1; i++)
              {
                  dr[i] = row.Cells[i].Text.Replace("&nbsp;", " ");
              }
              table.Rows.Add(dr);
          }


Am adding all the values to a table. The above code returns nothing for the first 2 columns of each and every row.

Can anybody help on this issue?

Thanks in Advance,

Joseph
Posted

1 solution

you might have first two columns as item templates which contains some other controls inside due to which .TEXT may retun string.Empty

Use
C#
row.Cells[i].FindControl('YourControlName')


i.e.

C#
//If you have a textBox inside
TextBox objText = (TextBox) row.Cells[i].FindControl('YourTextBoxId');
string value = objText.Text;
 
Share this answer
 
v2

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