的IList< T>和foreach [英] IList<T> and foreach

查看:74
本文介绍了的IList< T>和foreach的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我需要一些帮助,因为我不知道如何使用ILis

Hey guys, I need some help here, cause I don't know how to work with ILis

我正在尝试制作自己的博客和CMS,但我陷入了困境...

I'm trying to make my own blog and CMS, but i'm stuck in a point...

我与我的数据库(NHibernate,SQL Server)建立了连接,返回IList(下面的代码):

I Have a connection with my database (NHibernate, SQL Server), that return an IList (Code below):

public IList<Post> ReadPost(){
  using (ISession session = FluentySessionFactory.AbriSession())
  {
    ISQLQuery query = session.CreateSQLQuery("select Id, Title, Author, Subtitle, Content from tbl_post");
    query.AddEntity(typeof(Post));
    return query.List<Post>();
  }
 }






在我的blog.aspx上我有一个标签,在页面加载时执行此操作(示例):

And on my blog.aspx I have a label, that on page load do this (Example):

lblPost.Text = "<div class='list'><h1>" + Post.ReturnById(1).Title+ "</h1><h5>"+ Post.ReturById(1).Subtitle+ "</h5></div>";

Post.ReturnById()工作正常,但我需要说出我想要的内容。所以我需要它来制作一个搜索我的数据库中的每个Id并写在lblPost上的foreach。所以它可以像博客一样。

Post.ReturnById() is working perfect, but I need to say what Id I want. So what I need it to make a foreach that searches every Id on my database and write on lblPost. So it can be like a blog.

嗯,我认为这就是我需要的,如果还有其他方法,我会很乐意听到,因为它不需要完全在IList,但是我现在拥有的。

Well, I think that's what I need, if there is another way to do so, I will love to hear about, cause it don't need exactly to be in IList, but that what I have now.

推荐答案

如果你想把你的项目显示为List,你为什么不使用Repeater控件和将查询结果绑定到。
If you want to show your items as List, why don't you use the Repeater control and bind your query result to.


这篇关于的IList&LT; T&GT;和foreach的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆