Exemplo n.º 1
0
        private void BindGrid()
        {
            SqlDataReader dr = null;
            DataTable dt = new DataTable();
            BBSClass bbsclass = new BBSClass();
            BBSForumItem bbsforumitem = new BBSForumItem();
            bbsforumitem.BoardID = boardid;
            try
            {
                dr = bbsclass.GetBBSForumItem(bbsforumitem);
                dt = Tools.ConvertDataReaderToDataTable(dr);
                //��DataTable��ĩβ���Ͽ��У�ʹ��DataGrid�̶�����
                int blankrows = ItemList.PageSize - (dt.Rows.Count % ItemList.PageSize);
                for (int i = 0; i < blankrows; i++)
                {
                    dt.Rows.Add(dt.NewRow());
                }

                ItemList.DataSource = dt.DefaultView;
                ItemList.DataBind();

                string innerstring = "";
                //��ʾ��鹫��
                SqlDataReader dr_bulletin = bbsclass.GetBulletin(boardid);
                try
                {
                    while (dr_bulletin.Read())
                    {
                        innerstring += "<a href='display.aspx?ItemID=" + dr_bulletin["item_id"] + "&BoardID=" + boardid + "'title='" + dr_bulletin["content"] + "' target=_blank>" + dr_bulletin["title"].ToString() + "</a> (" + DateTime.Parse(dr_bulletin["send_time"].ToString()).ToString() + ") ";
                    }
                }
                finally
                {
                    dr_bulletin.Close();
                }
                mar_bulletin.InnerHtml = innerstring;

                innerstring = "";
                //��ʾϵͳ����
                SqlDataReader dr_sysbulletin = bbsclass.GetSysBulletin();
                try
                {
                    while (dr_sysbulletin.Read())
                    {
                        innerstring += "<a href='display.aspx?ItemID=" + dr_sysbulletin["item_id"] + "&BoardID=" + boardid + "'title='" + dr_sysbulletin["content"] + "' target=_blank>" + dr_sysbulletin["title"].ToString() + "</a>(" + DateTime.Parse(dr_sysbulletin["send_time"].ToString()).ToString() + ")";
                    }
                }
                finally
                {
                    dr_sysbulletin.Close();
                }
                sys_bulletin.InnerHtml = innerstring;
                //���ڿռ�¼����ʾͼƬ��������Ϣ
                for (int i = 0; i < ItemList.Items.Count; i++)
                {

                    if (ItemList.DataKeys[i].ToString() == "")
                    {
                        ItemList.Items[i].FindControl("bias").Visible = false;
                        ItemList.Items[i].FindControl("image").Visible = false;
                    }
                }

                lbl_totalrecord.Text = ItemList.PageCount.ToString();
                lbl_curpage.Text = txb_PageNo.Text = (ItemList.CurrentPageIndex + 1).ToString();
                txb_ItemPerPage.Text = ItemList.PageSize.ToString();
                lbl_totalpage.Text = ItemList.PageCount.ToString();

            }
            catch (Exception ex)
            {
                UDS.Components.Error.Log(ex.Message);
                Server.Transfer("../../Error.aspx");
            }
            finally
            {

                if (dr != null)
                {

                    dr.Close();
                }
            }
        }