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

上記の方法を使用すると、最後の行のみの cell[5] の値が取得されます。
したがって、特定の行に固有の場合は、他の gridview イベント ハンドラーから値を取得できると思います。

于 2011-07-01T16:03:05.990 に答える
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 に答える