ASP.NET控件开发基础(21)

http://tech.ddvip.com   2007年09月02日    社区交流

内容摘要:既然2.0版本已经提供了数据源控件,你是否有想法,让你原有的控件也升级到同时支持通过设置DataSource属性和数据源控件来获取数据源,这样以后我们就可以省省工作了。这次我们就来讨论这个话题,让旧版本的数据绑定控件支持数据源控件。

  3.获取数据源视图

  第二步的实现是为此服务的

private DataSourceView ConnectToDataSourceView()
{
  if (!currentViewValid || base.DesignMode)
  {
    if ((currentView != null) && currentViewIsFromDataSourceID)
    {
      currentView.DataSourceViewChanged -= new EventHandler(this.OnDataSourceViewChanged);
    }
  
    this.currentDataSource = GetDataSource();
  
    //从DataSource获取数据源
    if (this.currentDataSource == null)
    {
      this.currentDataSource = new ReadOnlyDataSource(DataSource, DataMember);
    }
  
    DataSourceView view = this.currentDataSource.GetView(DataMember);
    currentViewIsFromDataSourceID = IsBoundUsingDataSourceID;
    currentView = view;
  
    if ((currentView != null) && currentViewIsFromDataSourceID)
    {
      currentView.DataSourceViewChanged += new EventHandler(this.OnDataSourceViewChanged);
    }
    currentViewValid = true;
  }
  return currentView;
}
  
/// <summary>
/// 获取数据源视图
/// </summary>
/// <returns></returns>
protected virtual DataSourceView GetData()
{
  return ConnectToDataSourceView();
}

责编:豆豆技术应用

正在加载评论...