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>
我從它的父頁面綁定中繼器是這樣的。首先,我將中繼器的保護級別從保護級別更改爲公共級別,以便我可以從任何地方訪問它,而無需從父級頁面進行投射或查找。
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。這是相同的usercontrol被放置在頁面上的兩個地方。但是我綁定的時候空了。請幫助,我在哪裏做錯了什麼。