protected void dg_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataGrid dg1 = new DataGrid();
dg1.DataSource = ((DataView)((DataGrid)sender).DataSource).Table;
dg1.DataBind();
Page.Controls.Add(dg1);
}
}
无法将类型为“System.Web.UI.WebControls.GridView”的对象强制转换为类型“System.Web.UI.WebControls.DataGrid”。
------解决方案--------------------------------------------------------
你用的2005?
那么使用
GridView 而不是DataGrid
------解决方案--------------------------------------------------------
C#精髓【月儿原创】第四讲 GridView 72般绝技
http://blog.csdn.net/21aspnet/archive/2007/03/25/1540301.aspx
------解决方案--------------------------------------------------------
dg1.DataSource = ((DataView)((DataGrid)sender).DataSource).Table;=> dg1.DataSource = ((DataView)((GridView)sender).DataSource).Table;