[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
//===========================
// Version : ASP2.0
// Language : C#
//===========================
/// <summary>
/// GridView作成時
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
// データ表示行の場合
if (!(e.Row.RowType == DataControlRowType.DataRow))
{
// レコード操作用リンクボタンに行番号の引数を付与する
foreach (Control control in e.Row.Cells[2].Controls)
{
if (control is LinkButton)
{
LinkButton linkButton = (LinkButton)control;
linkButton.CommandArgument = System.Convert.ToString(e.Row.RowIndex);
}
}
}
}
/// <summary>
/// リンククリック時
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LinkButton1_Click1(object sender, EventArgs e)
{
LinkButton link = (LinkButton)sender;
string strKey = GridView1.Rows[int.Parse(link.CommandArgument)].Cells[1].Text;
Response.Redirect("リンク先?key=" + strKey);
}
// 引用
// http://www.techbank.jp/vbnet/CustomGridView.html
