Gridview循环获取单元格数据 [英] Gridview looping get cell data

查看:111
本文介绍了Gridview循环获取单元格数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

foreach (GridViewRow row in GridView3.Rows)
      {
          if (row.RowType == DataControlRowType.DataRow)
          {
              FileUpload chkRow = (row.Cells[7].FindControl("newdoc") as FileUpload);
              if (chkRow.HasFile)
              {
                  string test = row.Cells[2].Text;
                  data = data + "" + test + ",";
              }
          }
      }



i尝试在此行放置断点


i tried put breakpoint on this line

row.Cells[2].Text



我从测试中获得的结果总是为空/空......想法为什么?



我的尝试:



ntggggggggggggggggggggggggggggggggggggggg


result i get from test is always null/empty..any ideas why?

What I have tried:

ntggggggggggggggggggggggggggggggggggggggg

推荐答案

我怀疑你的第3列不是 BoundField

如果你想获得你的BoundField的内容,那么你可以使用

I suspect your column number 3 is not a BoundField.
If you want to get the content of your BoundField, then you can use
row.Cells[2].Text



但是,如果它是一个模板字段,那么你需要找到像你一样分配文本的控件已完成FileUpload控件。

ig,


But, if it is a template field then you need to find the control to which the text is assigned just like you have done for the FileUpload control.
i.g,

Label lbl= (Label) row.FindControl("lblName");





希望,它有帮助:)

如果我在这里错过了什么,请告诉我。



Hope, it helps :)
Please let me know if I am missing something here.


Gridview.Cells[i].Text will return value If it is a <asp:BoundField>



如果你有模板字段。你必须先找到控件然后找到它的值。它会起作用。


If you hvae Template field . you must find the control first then find the value of it . It will work.


这篇关于Gridview循环获取单元格数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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