How do I get the value of a gridview Cell?

会有一股神秘感。 提交于 2019-12-01 09:09:21

问题


How can I get the value of a gridview cell? I have been trying the code below with no luck.

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

回答1:


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

     }
   }



回答2:


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



回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/6549341/how-do-i-get-the-value-of-a-gridview-cell

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