小编Dam*_*iro的帖子

无法将lambda表达式转换为类型'string',因为它不是委托类型

我正在构建一个页面,将LINQ查询结果显示为表格.

  1. 在'SetupArticleQuery()'方法中设置基本查询,该方法将查询保存到'this.articles'.
  2. 运行另一个方法'UpdateFilter()'对'this.articles'中保存的结果进行一些过滤.

我收到了错误

无法将lambda表达式转换为类型'string',因为它不是委托类型

在代码行

this.articles = from art in this.articles
                where art.category_id == this.categoryId
                select art;
Run Code Online (Sandbox Code Playgroud)

任何想法如何修复下面的代码?

namespace WebApplication3 {
    public partial class _Default : System.Web.UI.Page {
        private IQueryable articles;

        protected void Page_Load(object sender, EventArgs e) {
            this.SetupArticleQuery();
            this.UpdateFilter();
        }

        private void SetupArticleQuery() {
            this.articles = from a in KB.Articles
                            join t in KB.Teams on a.primary_team_id equals t.id
                            join cat in KB.Categories on a.category_id equals cat.id
                            join scat in KB.SubCategories on a.subcategory_id equals scat.id
                            join top in KB.Topics …
Run Code Online (Sandbox Code Playgroud)

.net c# linq lambda extension-methods

8
推荐指数
3
解决办法
2万
查看次数

获取/设置为不同类型

我想定义一个接受SET中字符串的变量,然后将其转换为Int32并在GET期间使用它.

这是我目前拥有的代码:

private Int32 _currentPage;

public String currentPage
{
   get { return _currentPage; }
   set 
   {
      _currentPage = (string.IsNullOrEmpty(value)) ? 1 : Convert.ToInt32(value);
   }
}
Run Code Online (Sandbox Code Playgroud)

.net c# properties

7
推荐指数
1
解决办法
6447
查看次数

访问codebehind方法中的Repeater.Item.Count值

我的页面上有一个转发器:

<asp:Repeater id="attachmentsRepeater" runat="server">
    <HeaderTemplate>
        <% 
        if (attachmentsRepeater.Items.Count > 0) {
            if (attachmentsRepeater.Items.Count == 1) {
                Response.Write("<h3>Attachment</h3>");
                Response.Write("<p>");
            } else {
                Response.Write("<h3>Attachments</h3>");
                Response.Write("<ul>");
            }
        }
        %>
    </HeaderTemplate>
    <ItemTemplate>
        <%# OutputAttachment(Container)%>
    </ItemTemplate>  
    <FooterTemplate>
        <% 
        if (attachmentsRepeater.Items.Count > 0) {
            if (attachmentsRepeater.Items.Count == 1) {
                Response.Write("</p>");
            } else {
                Response.Write("</ul>");
            }
        }
        %>
    </FooterTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)

原始的ItemTemplate代码如下所示:

<ItemTemplate>
    <%
    if (attachmentsRepeater.Items.Count > 0) {
        if (attachmentsRepeater.Items.Count > 1) {
            Response.Write("<li>");
        }
        %>
        <a href="<%# DataBinder.Eval(Container.DataItem, "location") %>">
            <%# DataBinder.Eval(Container.DataItem, "name") %>
        </a>
        <% …
Run Code Online (Sandbox Code Playgroud)

c# methods repeater code-behind

5
推荐指数
1
解决办法
1万
查看次数