多用户回复留言板小结

      做这个留言板使我更加懂得了“工欲善其事,必先利其器”这句话.就是因为浏览器的缘故,使我的开发时间延长了,而且产生了厌倦的情绪.幸好上网偶遇了金出武雄博士的“像外行一样思考,像专家一样实践-----科研成功之道”,阅读了几章便大有裨益,最终沉下心来继续开发.
    小结一下这个留言板:
           其实也没什么特别,是用datalist来绑定数据的,且回复内容也是用datalist来绑定,就是说datalist中嵌套了datalist.
           主要应用到的事件有:ItemCommand,ItemDataBound
      ItemCommand(object sender, DataListCommandEventArgs e)事件主要是datalist中选中项的控件(主要是linkbutton,imagebutton)点击的事件的实现
              用e.commandName来跟控件配对.引发相应的事件.
              ItemDataBound(object sender, DataListItemEventArgs e)顾名思义是绑定数据用的,绑定时要先判断
                            (e.Item.ItemType == ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
                         
     红色部分刚开始没判断 导致后来去Id的时候只去到单数项的,这个印象很深!!
                              取ID是先设置datalist的datakeyfield,然后要用时(通常是更新,删除等操作时要用到)通过dalalist.DataKey["e.Item.ItemIndex"]
                            来取选中项的datakeyfield的值.

     然后是分页部分,没什么好讲的,直接上代码:
            

             PagedDataSource objPD = new PagedDataSource();
            objPD.DataSource = dv;
            objPD.AllowPaging = true;
            objPD.PageSize = 8;
            lbTotal.Text = "共" + "<font color=#ff0000>" + objPD.PageCount.ToString() + "</font>" + "页";
            int CurentPage;
            if (Request.QueryString["page"] != null)
            {
                CurentPage = Convert.ToInt32(Request.QueryString["page"]);
            }
            else
            {
                CurentPage = 1;
            }
            objPD.CurrentPageIndex = CurentPage - 1;
            lnkCur.Text = "当前第"+"<font color=#ff0000>" + CurentPage.ToString()+"</font>"+"页";

            if (!objPD.IsFirstPage)
            {

                lnkFirst.NavigateUrl = Request.CurrentExecutionFilePath + "?page=1";
                lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurentPage - 1);
            }
            else
            {
                lnkFirst.Visible = false;
                lnkPrev.Visible = false;
             
            }
            if (!objPD.IsLastPage)
            {

                lnkEnd.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(objPD.PageCount);
                lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurentPage + 1);
            }
            else
            {
                lnkEnd.Visible = false;
                lnkNext.Visible = false;
            }

            gbDl.DataSource = objPD;
            gbDl.DataBind();

        }
          这个东西虽然很基础,但发现做的时候,还不算熟练,以后要多练,基础很重要.
posted @ 2009-07-25 02:20  cetus  阅读(512)  评论(0编辑  收藏  举报