gridview
セルの値を取得するにはどうすればよいですか? 以下のコードを試してみましたが、うまくいきませんでした。
protected void grvExpirations_RowDataBound(object sender, GridViewRowEventArgs e) {
int test = Convert.toInt32(e.Row.Cells[5].text;
}
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";
}
}
}
protected void grvExpirations_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int test = Convert.toInt32(e.Row.Cells[5].Text);
}
}
上記の方法を使用すると、最後の行のみの cell[5] の値が取得されます。
したがって、特定の行に固有の場合は、他の gridview イベント ハンドラーから値を取得できると思います。
以下のコードを使用して、
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から始まることを覚えておいてください