当前位置:编程学习 > C#/ASP.NET >>

哪位朋友帮我解释一下这段代码啊,谢谢了!!!

public partial class forumlist : FunctionBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["type"] == null)
        {
            Response.Redirect("/code/forumindex.aspx");
            return;
        }
        newscontent.InnerHtml = ShowTopNews();
        string type_sql = "select * from forumtype where id=" + Request["type"];
        SqlDataReader type_sr = SQLBASE.ExecuteReader(type_sql);        
        if (type_sr.Read())
        {
            typetext.InnerHtml = type_sr["title"].ToString();
            Page.Title = type_sr["title"].ToString();
        }
        if (Session["username"] != null)
        {
            showimg.InnerHtml += "<a href='/code/forumreply.aspx?action=newforum&type=" + Request["type"] + "' target='_self'><img alt='发新话题' border='0' src='/code/images/newtopic.gif' /></a> ";
        }

        string list_sql = "select forum.*,reg1.username from forum "
                            +"left join reguser as reg1 on reg1.rid=forum.initiator "
                            +"where type='" + Request["type"] + "'";
        DataSet ds = SQLBASE.FillDataSet(list_sql);
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            DataRow row = ds.Tables[0].Rows[i];
            
            /*******************总回复人数********************************/
            string revert_sql = "select count(id) as total from enlistforum where forumid=" + row["forumid"];
            SqlDataReader sr = SQLBASE.ExecuteReader(revert_sql);
            int total = 0;
            if (sr.Read()==true)
            {
                total = (int)sr[0];
            }
            /******************最后回贴人*********************************/
            string lastrevert_sql = "select top 1 enlistforum.*,reguser.username from enlistforum left join reguser on enlistforum.pid=reguser.rid where forumid=" + row["forumid"] + "order by enlistdate desc";
            SqlDataReader last_sr = SQLBASE.ExecuteReader(lastrevert_sql);
            string lastText = "无回复";
            if (last_sr.Read()==true)
            {
                lastText = last_sr["enlistdate"].ToString() + " by " + last_sr["username"].ToString();
            }

            string imgurl = "";
            if ((int)row["isclose"] != 1)
            {
                if (total>10)
                {
                    imgurl = "<img src='/code/images/red_folder.gif' border='0' alt='热点帖子' />";
                }
                else imgurl = "<img src='/code/images/folder.gif' border='0' alt='普通帖子' />";
            }
            else
            {
                imgurl = "<img src='/code/images/lock_folder.gif' border='0' alt='该主题帖子已经关闭' />";
            }

            smallforumlist.InnerHtml+=
                "<tr>"
            +"<td style='width: 5%; height:30px;background-color:#FFFfFF' align='center' valign='middle'>"+imgurl
            +"</td>"
            +"<td style='width: 5%; height:30px;background-color:#F8F8F8' align='center' valign='middle'>"
            +"</td>"
            + "<td style='width: 50%; height:30px;background-color:#FFFfFF' align='left' valign='middle'> <a href='/code/forumdisplay.aspx?forumid=" + row["forumid"] + "' target='_blank' title='点击查看详细内容'>" + row["title"]+"</a>"
            +"</td>"
            + "<td style='width: 20%; height:30px;background-color:#F8F8F8' align='center' valign='middle'>" + row["createdate"] + " by " + row["username"]
            +"</td>"
            + "<td style='width: 5%; height:30px;background-color:#FFFfFF' align='center' valign='middle'>" + total
             +" </td>"
            + "<td style='width: 15%; height:30px;background-color:#F8F8F8' align='center' valign='middle'>" + lastText
            +"</td>"
        +"</tr>";
        }
        //smallforumlist.InnerHtml = "";
    }
--------------------编程问答-------------------- 很多分啊 --------------------编程问答-------------------- 帮顶 --------------------编程问答-------------------- 看大概文件是回复帖子的语句~page_load里是判断request请求和session里是否为空,为空则不能回复!不为空就跳转到'/code/forumreply.aspx?action页面,当然这个页面是带参数的:newforum&type=" + Request["type"] + "' target='_self'!最后回帖人里的语句是判断分页的和查看的!

另: SqlDataReader 这个是绑定控件语句,就是将从数据库中的查出的内容转换到sr 字符集里!而 DataRow row 语句是控件里的行数!至于SQL语句我就不用解释了吧?

我的联系方式是MSN:lindblum_88@hotmail.com,要是还有不清楚的地方联系我!
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,