当前位置: 代码迷 >> ASP.NET >> |M| 大家帮看一下下面在Row绑定的时候得到绑定控件的数据源哪里写得不对,该如何处理
  详细解决方案

|M| 大家帮看一下下面在Row绑定的时候得到绑定控件的数据源哪里写得不对,该如何处理

热度:8885   发布时间:2013-02-26 00:00:00.0
|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;
  相关解决方案