无法读取gridview中一行的前两列 [英] Cannot read the first two columns of a row in a gridview

查看:62
本文介绍了无法读取gridview中一行的前两列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我需要读取gridview中一行的allcolumns。我使用以下代码来执行此操作。



Hi all,

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

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);
          }





将所有值添加到表中。上面的代码没有为每一行的前两列返回任何内容。



有人可以帮忙解决这个问题吗?



先谢谢,



Joseph



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

推荐答案

你可能有前两列项目模板,其中包含一些其他控件,因为.TEXT可以重新调整string.Empty



使用

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

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

< br $> b $ b

ie





i.e.

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


这篇关于无法读取gridview中一行的前两列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆