aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridToTextBox.aspx.cs" Inherits="ListControls_GridToTextBox" %>
aspx.cs
using System;
using System.Web.UI.WebControls;
using System.Data;
public partial class ListControls_GridToTextBox : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.GridView1.DataSource = this.GetData();
this.GridView1.DataBind();
}
}
///
/// 임의 데이타 바인딩
///
/// DataTable
private DataTable GetData()
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add("idx");
dt.Columns.Add("title");
dt.Columns.Add("regdate");
for (int i = 0; i < 11; i++)
{
dr = dt.NewRow();
dr["idx"] = i.ToString();
dr["title"] = String.Format("{0} 번째 제목", i.ToString());
dr["regdate"] = DateTime.Now.AddDays(i).ToString("yyyy-MM-dd");
dt.Rows.Add(dr);
dt.AcceptChanges();
}
return dt;
}
///
/// RowDataBound ; 클릭시 어트리뷰트
///
///
///
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drv = (DataRowView)e.Row.DataItem;
//텍스트 박스에 표시하고 하는 데이타를 특정구분자로 구분지어 병합
string strAttribute = String.Format("dataInTextBox('{0}|{1}|{2}')", drv["idx"].ToString(), drv["title"].ToString(), drv["regdate"].ToString());
//row(tr)에 onclick event
e.Row.Attributes.Add("onclick", strAttribute);
//커서 손가락 모양
e.Row.Style.Add("cursor", "hand");
}
}
}