GridViewの特定の行だけ背景色を変えたりボタンを使えないようにする
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[7].Text == "1")
{
e.Row.BackColor = System.Drawing.Color.Gray;
e.Row.Cells[0].Enabled = false;
}
if (e.Row.Cells[6].Text == "RETURN")
{
e.Row.BackColor = System.Drawing.Color.Firebrick;
e.Row.Cells[0].Enabled = false;
}
}
}
TemlateFieldのボタンのCommandArgumentに値をセットする
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button cancel = (Button)e.Row.Cells[0].Controls[1];
cancel.CommandArgument = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
//cancel.CommandArgument = e.Row.RowIndex.ToString();
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
TextBox1.Text = e.CommandArgument.ToString();
}
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button cancel = (Button)e.Row.Cells[0].Controls[1];
cancel.CommandArgument = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
//cancel.CommandArgument = e.Row.RowIndex.ToString();
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
TextBox1.Text = e.CommandArgument.ToString();
}