Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法将标题模板与L2S IQueryable列表绑定_C#_Asp.net_.net_Linq_Linq To Sql - Fatal编程技术网

C# 无法将标题模板与L2S IQueryable列表绑定

C# 无法将标题模板与L2S IQueryable列表绑定,c#,asp.net,.net,linq,linq-to-sql,C#,Asp.net,.net,Linq,Linq To Sql,我的方法如下所示: internal IQueryable<TradeLeads> GetLeadsByCategory(int categoryId) { return _context.BuySells.Where(bs => bs.CategoryId == categoryId).OrderBy(bs => bs.CreationDate).Select(

我的方法如下所示:

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
                              });
        }
内部IQueryable GetLeadsByCategory(int categoryId)
{
返回
_context.buysals.Where(bs=>bs.CategoryId==CategoryId).OrderBy(bs=>bs.CreationDate).选择(
bs=>新贸易线索
{
Id=bs.Id,
BuySellTypeId=Convert.ToInt32(bs.BuySellTypeId.ToString()),
描述=bs.描述,
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()),
后置日期=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>

我从它的父页面绑定repeater,类似这样的东西。首先,我将中继器的保护级别从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);
        }
private void BindAllBuyAndSellLeads(int categoryId)
{
var repo=新的LeadsRepository();
var列表=回购GetLeadsByCategory(categoryId);
BindGrid(1,Leads1.LeadsGrid,列表);
BindGrid(2,Leads2.LeadsGrid,列表);
}
私有静态void BindGrid(int leadTypeId、中继器gv、IQueryable列表)
{
var query=(来自列表中的p)
其中p.BuySellTypeId==leadTypeId
选择p.ToList();
Common.BindGrid(查询,gv);
}

此处导线1和导线2是用户控制导线.ascx。也就是说,相同的用户控件放置在页面的两个位置。但是我在装订的时候变得空了。请帮助我,我哪里做错了,哪里做错了,我做错了什么。

标题中的绑定永远不会起作用。绑定仅适用于ItemTemplate;您可以通过编程设置报头中的值,但要知道中继器用于绑定多行数据;有多个项目,但只有一个标题。应该使用哪个BuySellTypeId?第一个?最后一个?中继器无法判断,因此必须通过编程设置该值