日期:2014-05-18  浏览次数:20505 次

GridView模版列e.Row.Cell[0].Text问题???
<asp:TemplateField HeaderText="Delete">
  <ItemTemplate>
  <asp:Label ID="LabelJobId" Text=<%#Eval("job_id")%> runat="server" />
  </ItemTemplate>
</asp:TemplateField>


protected void GridView1_RowDataBound ( object sender, GridViewRowEventArgs e )
  {
  string result = e.Row.Cell[0].Text;
  }

对于模版列,e.Row.Cell[0].Text为什么是空呢?
而对于<asp:BoundField>绑定列来说e.Row.Cell[0].Text是可以使用的,为什么?

------解决方案--------------------
因为你已经用了 TemplateField 啊!

这表明GridView已不再存在第一列数据显示了。所以当前Text当然为空咯。
------解决方案--------------------
用FindControl找到你需要的控件,然后取值
------解决方案--------------------
string result = ((Label) e.Row.FindControl("LabelJobId")).Text; 

------解决方案--------------------
e.Row.Cell[1].Text
你换成1试一试 应该是1有值
------解决方案--------------------
((DataBoundLiteralControl)grid.Rows[i].Cells[3].Text

protected void GridView1_RowDataBound ( object sender, GridViewRowEventArgs e ) 

string result = ((DataBoundLiteralControl)e.Rows[1].Cells[3].Text } 

摸版列
------解决方案--------------------
((DataBoundLiteralControl)grid.Rows[i].Cells[3].Controls[0]).Text 

------解决方案--------------------
C# code

Label LabelJobId= GridViewList.Rows[i].Cells[0].FindControl("LabelJobId") as Label;
string   result   =LabelJobId.Text;