关于对PagedDataSource的相关操作,引起的思考和实践

在这次的课程设计中,文章的分类为int,在显示的时候需要根据这个数到另一个表中去查找相应的类别名称,我当时图省事,向在blog.aspx页面下面搞点手脚,可是不能将EVAL("")用于非字段绑定的上下文中,最后,突然想到了,pageddatasource的数据源实际上我是给了一个list类,所以实际上,可以在数据访问层,再查询一次数据库,因此在Article类中加入了leibiestr,然后在读取的时候,重新到leibietable中再读一次值,具体的代码可以看看:呵呵,


新加入了leibie类,和leibieoperater类,下面的黑体字是新加入的代码!---有思路就有出路,拽拽!!


public List<Article> viewAll()
    {
        List<Article> list = new List<Article>();
        con.Open();
        cmd = new SqlCommand("select * from newstable order by time desc", con);
        SqlDataReader sdr = cmd.ExecuteReader();
        Article ac;
        Leibie lb = null;
        LeibieOperater lbo = null;
        while (sdr.Read())
        {
            lb = new Leibie();
            lbo = new LeibieOperater();
            ac = new Article();
            ac.id= sdr["id"].ToString();
            ac.liebie =Convert.ToInt32(sdr["leibie"]);
            int i = ac.liebie;
            lb = lbo.getbyid(i);
            ac.leibiestr = lb.leibie.ToString();
            ac.title = sdr["title"].ToString();
            ac.content = sdr["content"].ToString();
            if (ac.content.Length > 200)
            {
                ac.content = ac.content.Substring(0, 200);
            }
            ac.postdatetime = Convert.ToDateTime(sdr["time"]);
            ac.gentieCount = Convert.ToInt32(sdr["GentieCount"]);
            ac.readcount = Convert.ToInt32(sdr["times"]);//读了多少次
            ac.author = sdr["author"].ToString();
            list.Add(ac);
        }
        sdr.Close();
        con.Close();
        return list;
    }

评论

此博客中的热门博文

Linux/ARM Page Table Entry 属性设置分析

提交了30次才AC ---【附】POJ 2488解题报告

笔记