通过Row.Cells访问Gridview列

Khi*_*zar 4 .net c# asp.net gridview

Hai我使用以下代码来连续访问列,但在使用Row.Cells[1].Text时总是显示空字符串我在GridView Unload事件处理程序中使用此代码.

谢谢客栈提前.

foreach (GridViewRow row in grvSearchRingTone.Rows)
{
    String coltext = row.Cells[1].Text;
}
Run Code Online (Sandbox Code Playgroud)

Muh*_*tar 5

我建议Gridview Databound event改用.因为

从内存中卸载服务器控件时发生卸载事件.

protected void  GridView1_DataBound(object sender, EventArgs e)
{
  foreach (GridViewRow row in grvSearchRingTone.Rows)
  {
    String coltext = row.Cells[1].Text;
  }
}
Run Code Online (Sandbox Code Playgroud)

数据绑定事件在服务器控件绑定到数据源之后发生.

要了解gridview事件的工作原理,请查看MSDN