您的位置:首页 > Web前端 > JavaScript

JS访问GridView中的模板控件

2010-10-11 21:30 260 查看
后台代码

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("name");
dt.Columns.Add("age");

DataRow dr = dt.NewRow();
dr["name"] = "Dolphin";
dr["age"] = 18;
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["name"] = "Fish";
dr["age"] = 19;
dt.Rows.Add(dr);

this.GridView1.DataSource = dt.DefaultView;
this.GridView1.DataBind();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button rb = (Button)e.Row.FindControl("btnInfo");
TextBox tb = (TextBox)e.Row.FindControl("txtInfo");
string strName = e.Row.Cells[1].Text.ToString();
string strAge = e.Row.Cells[2].Text.ToString();

if (rb != null)
{
rb.Attributes.Add("onclick", "return onClientClick('" + rb.ClientID + "','"+tb.ClientID+"','"+strName+"','"+strAge+"')");
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: