2012-02-10 10 views
0

とヘッダーテンプレートをバインドすることができません私は、下記IQuerableを返すメソッドを持っています。L2SのIQueryableリスト

internal IQueryable<TradeLeads> GetLeadsByCategory(int categoryId) 
     { 
      return 
       _context.BuySells.Where(bs => bs.CategoryId == categoryId).OrderBy(bs => bs.CreationDate).Select(
        bs => new TradeLeads 
           { 
            Id = bs.Id, 
            BuySellTypeId = Convert.ToInt32(bs.BuySellTypeId.ToString()) , 
            Description = bs.Description, 
            Flag = bs.Company.Country1.Flag, 
            MembershipType = bs.Company.MembershipType, 
            IsUsingSmsNotifications = bs.Company.IsUsingSMSNotifications, 
            IsVerified = bs.Company.IsVerified, 
            ProductImagePath = bs.ProductImagePath, 
            ProductName = bs.ProductName, 
            CompanyName = bs.Company.CompanyName, 
            CompanyId = Convert.ToInt32(bs.CompanyId.ToString()), 
            PostedDate = bs.CreationDate 
           }); 
     } 

すべてのフィールドが値を持っています。リピータコントロールのヘッダーテンプレートにBuySellTypeIdをバインドしています。 ASPXはUsercontrolにあります。

<HeaderTemplate> 
     <div class="grdheader"> 
      <div class="hdrText"> 
       <h3 id="h3TypeName"> 
        </h3> <asp:HiddenField runat="server" ID="HidTypeId" Value='<%#Eval("BuySellTypeId") %>'/> 
      </div> 
      <div class="hdrMore"> 
       <a href='<%#string.Format("ViewAll.aspx?t={0}",Eval("BuySellTypeId"))%>'> 
        <img src="cdn/images/more.png" /> 
        View More </a> 
      </div> 
     </div> 
    </HeaderTemplate> 

私はこのような親ページからリピーターをバインドしています。最初に、リピータの保護レベルをprotectedからpublicに変更しました。これにより、キャストまたは親ページからの検索なしでどこからでもアクセスできます。

private void BindAllBuyAndSellLeads(int categoryId) 
     { 
      var repo = new LeadsRepository(); 
      var list = repo.GetLeadsByCategory(categoryId); 
      BindGrid(1, Leads1.LeadsGrid, list); 
      BindGrid(2, Leads2.LeadsGrid, list); 
     } 
     private static void BindGrid(int leadTypeId, Repeater gv, IQueryable<Core.Helper.TradeLeads> list) 
     { 
      var query = (from p in list 
         where p.BuySellTypeId == leadTypeId 
         select p).ToList(); 
      Common.BindGrid(query, gv); 
     } 

ここで、Leads1とLeads2はユーザーコントロールLeads.ascxです。つまり、同じユーザーコントロールがページ上の2か所に配置されます。しかし、私はバインディング中に空になっています。私が間違ってやっているところ、助けてください。

答えて

1

ヘッダーにバインドすることはできません。バインディングはItemTemplateのみです。プログラム可能にヘッダーの値を設定できますが、リピーターは複数の行のデータをバインドするためのものであることがわかります。複数の項目がありますが、ヘッダーは1つのみです。どちらがBuySellTypeIdを使用する必要がありますか?最初の1つ?最後のもの?リピーターが伝える方法はないので、プログラマブルに値を設定する必要があります。