Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Creating an object of the CMSDB class to call the 'ViewPage(int pageid)' functions in the database file.
            CMSDB db = new CMSDB();

            //Getting the pageid passed in the URL to select the current page from the database
            string pageid = Request.QueryString["pageid"];

            //If pageid is empty the custom error message will be written, otherwise the page details will be fetched from the database.
            if (String.IsNullOrEmpty(pageid))
            {
                pageId.InnerHtml = "Error findinf the page.";
            }
            else
            {
                //Creating an object of HTTP_Page to hold the HTTP_Page object which will be returned by the db.ViewPage(pageId) funciton.
                HTTP_Page page_record = db.ViewPage(Int32.Parse(pageid));

                //Using getters to get the values from the page_record and putting them in their respective <div> tags.
                page_title.InnerHtml = page_record.GetPageTitle();
                page_body.InnerHtml  = page_record.GetPageContent();

                //Creating a DateTime object which will hold the PUBLISHDATE received from the database.
                DateTime date = Convert.ToDateTime(page_record.GetPagePublishDate());

                //Converting the date into the 'DD/MMM/YYYY/ format and writing them in the required div tags.
                page_publish_date.InnerHtml += date.ToString("dd/MMM/yyyy");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //If the page is not being loaded in response to a postBack the ShowPage()
                CMSDB db = new CMSDB();

                // The below section of code is used to get the List of Authors from the Page table and display them in a dropdown box. Similar to CreatePage.aspx.cs
                List <HTTP_Page> pageList = new List <HTTP_Page>();
                pageList = db.ListPages("select distinct pageauthor from page;");
                foreach (HTTP_Page page in pageList)
                {
                    ListItem item = new ListItem();
                    item.Text  = page.GetPageAuthor();
                    item.Value = page.GetPageAuthor();
                    page_author_list.Items.Add(item);
                }
                ListItem newAuthorItem = new ListItem();
                newAuthorItem.Text  = "-------------- Add a new Author --------------";
                newAuthorItem.Value = "New";
                page_author_list.Items.Add(newAuthorItem);


                //Getting the pageid from the Request object
                string pageid = Request.QueryString["pageid"];

                //If pageid is empty the custom error message will be written, otherwise the page details will be fetched from the database and shown in the input fields.
                if (String.IsNullOrEmpty(pageid))
                {
                    page_update.InnerHtml = "There was an error finding that student.";
                }
                else
                {
                    HTTP_Page page_record = db.ViewPage(Int32.Parse(pageid));
                    page_update.InnerHtml          = page_record.GetPageTitle();
                    page_title.Text                = page_record.GetPageTitle();
                    page_content.Text              = page_record.GetPageContent();
                    page_author_list.SelectedValue = page_record.GetPageAuthor();
                    page_publish_date.Text         = page_record.GetPagePublishDate();
                }
            }
        }