RowDataBound用法

GridView1_RowDataBound用法:

(1)别绑定的数据为为一个对象实例:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            b ca = e.Row.DataItem as b;//b为自定义的类
            (e.Row.FindControl("Label1") as Label).Text = ca.Test.ToString();
            (e.Row.FindControl("Label2") as Label).Text = ca.Testa.ID.ToString();
        }
    }
(2)绑定dataTable
 protected void gridJoin_RowDataBound(object sender, GridViewRowEventArgs e)
{

         if (e.Row.RowType == DataControlRowType.DataRow)
         {
             string jj = (e.Row.DataItem as DataRowView).Row["parent_id"].ToString();
             //string jj = (e.Row.DataItem as DataRowView)["parent_id"].ToString();//此方法亦可
             ClientScript.RegisterClientScriptBlock(this.GetType(), jj, "alert('" + jj + "');", true);
         }
}

posted on 2008-08-09 09:36  张皓  阅读(931)  评论(0编辑  收藏  举报

导航