How do I get the value of a gridview Cell?

后端 未结 4 1408
遥遥无期
遥遥无期 2021-01-14 20:14

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         


        
相关标签:
4条回答
  • 2021-01-14 20:45

    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

    0 讨论(0)
  • 2021-01-14 20:51
     protected void grvExpirations_RowDataBound(object sender, GridViewRowEventArgs e)
       {
          if (e.Row.RowType == DataControlRowType.DataRow)
         {
           int test = Convert.toInt32(e.Row.Cells[5].Text);
    
         }
       }
    
    0 讨论(0)
  • 2021-01-14 21:04

    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.

    0 讨论(0)
  • 2021-01-14 21:05
    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"; 
                }  
            }  
        } 
    
    0 讨论(0)
提交回复
热议问题