How do I get the value of a gridview Cell?

我只是一个虾纸丫 提交于 2019-12-01 11:20:33
 protected void grvExpirations_RowDataBound(object sender, GridViewRowEventArgs e)
   {
      if (e.Row.RowType == DataControlRowType.DataRow)
     {
       int test = Convert.toInt32(e.Row.Cells[5].Text);

     }
   }
Rasith
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"; 
            }  
        }  
    } 

use this code below,

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

and please remember cell index number starts from 0

If you use the above methods you will get the value of cell[5] for the last row only.
So if you are specific about a certain row I think you can get the value from any other gridview event handlers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!