当前位置: 代码迷 >> ASP.NET >> 动态加载GridViewRowEventHandler事件有关问题
  详细解决方案

动态加载GridViewRowEventHandler事件有关问题

热度:2871   发布时间:2013-02-26 00:00:00.0
动态加载GridViewRowEventHandler事件问题!

  RoomList   =   (GridView)e.Item.Cells[0].FindControl( "GridView2 ");  
                      RoomList.DataSource   =   RangInfo.GetDataSet();
                        RoomList.DataBind();//注数据也显示在页面上。

                        RoomList.RowDataBound   +=   new   GridViewRowEventHandler(RoomList_DataBound);  
e.Item.Attributes.Add( "onmouseover ",   "this.style.backgroundColor= '#E4EDF9 ' ");//以执行可以颜色可以改变。

  protected   void   RoomList_DataBound(object   sender,   GridViewRowEventArgs   e)
        {
                Response.Write( "没有执行 ");
        }


事件:RoomList.RowDataBound   +=   new   GridViewRowEventHandler(RoomList_DataBound);   这句为什么就不行呢!!

------解决方案--------------------------------------------------------
加载的时机不对

------解决方案--------------------------------------------------------
放在DataBind() 前面

RoomList.RowDataBound += new GridViewRowEventHandler(RoomList_DataBound);

RoomList.DataSource = RangInfo.GetDataSet();
RoomList.DataBind();//注数据也显示在页面上。

  相关解决方案