日期:2014-05-19  浏览次数:20496 次

|M| 大家帮看一下下面在Row绑定的时候得到绑定控件的数据源哪里写得不对
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;