У меня есть метод, который возвращает IQuerable, указанный ниже:
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. То есть один и тот же пользовательский контроль размещается в двух местах на странице. Но я становлюсь пустым во время привязки. Пожалуйста, помогите, где и что я делаю не так.