Repeater 前台指定DataSource 数据源是后台的一个DataTable。

解决方案 »

  1.   

    DataSource”属性只能由运行时设置。不能对它进行声明。
      

  2.   

    孟子有个是这样指定
    DataSource='<%# Ctype(Container.DataItem,DataRowView).CreateChildView("OrderRelation") %>'>可是我想在repeater中指定一个datatable怎么不可以呢?
      

  3.   

    Repeater1.DataSource=DataTable;
    Repeater1.DataBind();
      

  4.   

    原因是这样的,我在repeater中
    <asp:datagrid id="dgMSOList" Width="100%" runat="server" AllowSorting="True" AutoGenerateColumns="False">
    <Columns>
    <asp:BoundColumn Visible="False" DataField="ID" HeaderText="ID"></asp:BoundColumn>
    <asp:TemplateColumn>
    <ItemTemplate>
    <TABLE cellSpacing=1 cellPadding=4 width="100%" bgColor=#c9c9c9 border=0>
    <TR>...........
    这个table中我嵌套了一个repeater////////////////////////////////////////////////////////////////////////
    有个好奇怪的问题 我只有绑定才能正确显示
    如果我在后台 findcontrol的话就显示 未将对象引用到实例
      

  5.   

    Anders_lt(突破渴望) ( ) 信誉:98    Blog  2006-12-05 14:20:21  得分: 0  
     
     
       Repeater1.DataSource=DataTable;
    Repeater1.DataBind();
      
     
    //////////////////////////////////////
    哭啊~~~
    那个我当然知道
      

  6.   

    孟子有个是这样指定
    DataSource='<%# Ctype(Container.DataItem,DataRowView).CreateChildView("OrderRelation") %>'>
    这也是在运行时指定的.是在运行外层控件时,绑定这个控件.
      

  7.   


    DataRowView drv = ( DataRowView )e.Item.DataItem; DataTable dtDetail = new DataTable(); DataRow[] drs = dt.Select("code='"+ drv[ "code" ].ToString().Trim() +"'");    if ( drs.Length > 0 )
    {
    for ( int i = 0; i< drs.Length; i++ )
    {
    dtDetail.ImportRow( drs[ i ] );
    }
    }
    Repeater prt;
    prt = ( Repeater )e.Item.FindControl( "rptDetail" );
    prt.DataSource = dtDetail;
    prt.DataBind();--------------------------------------------------------------------------------
    上面是我从datatable中筛选出来的数据然后赋给一个datatable,把这个datatable指定到嵌套的repeater中,问题出现在:
    FindControl 找不到!!!!
    而且我放入别的控件一样找不到!!
    奇怪!!!
      

  8.   

    上面的代码是在ItemDataBound事件中还是ItemDataCreate事件中?在ItemDataBound才可.
    另外你也要判断一下. e.Item.ItemType.因为在HeaderItem或footerItem 中肯定是没有这个控件的.
      

  9.   

    <asp:DataGrid ....OnItemDataBound="BindScript"></...>
    public void BindScript(object src,DataGridItemEventArgs e)
    {
    if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
    {
    ...}
    }