2

如何获取gridview单元格的值?我一直在尝试下面的代码,但没有成功。

protected void grvExpirations_RowDataBound(object sender, GridViewRowEventArgs e) {
  int test = Convert.toInt32(e.Row.Cells[5].text;
}
4

4 回答 4

4
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {   
        if(e.Row.RowType == DataControlRowType.DataRow)  
        {  
             string LinkText = (string)System.Web.UI.DataBinder.Eval(e.Row.DataItem, "RegistrationLinkText"); 
            if(LinkText == "text")  
            {  
                e.Row.Cells[3].Text = "your text"; 
            }  
        }  
    } 
于 2012-12-04T07:58:24.720 回答
1
 protected void grvExpirations_RowDataBound(object sender, GridViewRowEventArgs e)
   {
      if (e.Row.RowType == DataControlRowType.DataRow)
     {
       int test = Convert.toInt32(e.Row.Cells[5].Text);

     }
   }
于 2011-07-01T14:53:15.153 回答
0

使用下面的代码,

 protected void grvExpirations_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int test = Convert.ToInt32(Server.HtmlDecode(e.Row.Cells[5].Text.Trim()));
        }
    }

请记住单元格索引号从 0 开始

于 2011-07-01T14:51:56.363 回答
0

如果您使用上述方法,您将仅获得最后一行的 cell[5] 的值。
因此,如果您具体了解某一行,我认为您可以从任何其他 gridview 事件处理程序中获取值。

于 2011-07-01T16:03:05.990 回答