protected void Page_Load(object sender, EventArgs e) { // The below section of code is used to get the List of Authors from the Page table and display them in a dropdown box. CMSDB db = new CMSDB(); List <HTTP_Page> pageList = new List <HTTP_Page>(); //Query to select distinct Authors from the table to be displayed in the dropdown box. pageList = db.ListPages("select distinct pageauthor from page;"); //Code to insert the list of Authors in the dropdown menu 'page_author_list' present in CreatePage.aspx. ***Not a part of the initial wireframe*** //Using the foreach loop Authors are retrieved from the pageList object and stored in 'ListItem' which will be added to the drop down list. foreach (HTTP_Page page in pageList) { ListItem item = new ListItem(); item.Text = page.GetPageAuthor(); item.Value = page.GetPageAuthor(); page_author_list.Items.Add(item); } //Adding a final List Item which will be used to 'add new authors' into the table. Clicking this will show another textbox in which new author can be added. ListItem newAuthorItem = new ListItem(); newAuthorItem.Text = "-------------- Add a new Author --------------"; newAuthorItem.Value = "New"; page_author_list.Items.Add(newAuthorItem); }
protected void Page_Load(object sender, EventArgs e) { //Creating an object for the CMSDB file to call its functions. CMSDB db = new CMSDB(); //Query to select the pages which are published string query = "select * from page where pagestatus=true"; //Creating an List of <HTTP_Page> object to hold the List of objects returned by the 'public List<HTTP_Page> ListPages(string query)' method in CMSDB. List <HTTP_Page> pageList = db.ListPages(query); //Code to insert the HTML markup using the 'InnerHtml' property of the 'UserControlHeading1' div tag UserControlHeading1.InnerHtml = "<ul class=\"nav navbar-nav\">"; foreach (HTTP_Page page in pageList) { UserControlHeading1.InnerHtml += "<li><a runat=\"server\" href=\"ViewPage.aspx?pageid=" + page.GetPageId().ToString() + "\">" + page.GetPageTitle() + "</a></li>"; } UserControlHeading1.InnerHtml += "</ul>"; }
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(); } } }
protected void Page_Load(object sender, EventArgs e) { //Creating a CMSDB object to call the ListPages(String query) function. CMSDB db = new CMSDB(); //Query that will be passed to the ListPages(String query) function. String query = "Select * from Page"; //Code to get the text entered in the searchbox. string searchkey = ""; if (Page.IsPostBack) { searchkey = page_title_search.Text; } //If text is entered in the searchbox a 'Where' clause with 'like' is added to the query. if (searchkey != "") { query += " WHERE PAGETITLE like '%" + searchkey + "%' "; } //Creating an List of <HTTP_Page> object to hold the List of objects returned by the 'public List<HTTP_Page> ListPages(string query)' method in CMSDB. List <HTTP_Page> pageList = db.ListPages(query); //Code to loop through pageList, which contains a List of HTTP_Page object, and get the required details which will be appeded to the table. foreach (HTTP_Page page in pageList) { //Getting the required fields from each record in the table. int pageid = page.GetPageId(); string pagetitle = page.GetPageTitle(); string pageauthor = page.GetPageAuthor(); string pagepublishdate = page.GetPagePublishDate(); //Creating a DateTime object to hold the Page Publish Date. DateTime date = Convert.ToDateTime(pagepublishdate); string pagepublishstatus = page.GetPagePublishStatus().ToString(); //Creating a HtmlTableRow object trow which will be used to store a single row and eventually be inserted in the HTML markup's <table id="table1"> tag HtmlTableRow trow = new HtmlTableRow(); //Creating a HtmlTableCell object which will contain individual cells that will be put into the HtmlTableRow tRow that was just created. HtmlTableCell cell1 = new HtmlTableCell(); if (pagepublishstatus.ToLower() == "true") { cell1.InnerHtml = "<a href=\"ViewPage.aspx?pageid=" + pageid + "\">" + pagetitle + "</a>"; } else { cell1.InnerText = pagetitle; } //Adding the current HtmlTableCell (cell1) in the HttpTableRow tRow. trow.Controls.Add(cell1); //Creating and adding HtmlTableCell (cell2) in the HttpTableRow tRow. HtmlTableCell cell2 = new HtmlTableCell(); cell2.InnerText = pageauthor; trow.Controls.Add(cell2); //Creating and adding HtmlTableCell (cell3) in the HttpTableRow tRow. HtmlTableCell cell3 = new HtmlTableCell(); //Displaying the Date in the 'dd/MMM/yyyy' format in the markup by using the ToString function of dateTime. cell3.InnerText = date.ToString("dd/MMM/yyyy"); trow.Controls.Add(cell3); //Creating and adding HtmlTableCell (cell4) in the HttpTableRow tRow. HtmlTableCell cell4 = new HtmlTableCell(); if (pagepublishstatus.ToLower() == "true") { cell4.InnerHtml = "<p> Published </p>"; } else { cell4.InnerHtml = "<p> Unpublished </p>"; } trow.Controls.Add(cell4); //Creating and adding HtmlTableCell (cell5) in the HttpTableRow tRow. HtmlTableCell cell5 = new HtmlTableCell(); if (pagepublishstatus.ToLower() == "true") { cell5.InnerHtml += "<input type=\"button\" value=\"View\" onclick=\"location.href='ViewPage.aspx?pageid=" + page.GetPageId().ToString() + "'\" class=\"btn btn-primary rowButton\"/>"; } else { cell5.InnerHtml += "<input type=\"button\" value=\"View\" onclick=\"location.href='ViewPage.aspx?pageid=" + page.GetPageId().ToString() + "'\" class=\"btn btn-primary rowButton\" disabled/>"; } cell5.InnerHtml += "<input type=\"button\" value=\"Edit\" onclick=\"location.href='UpdatePage.aspx?pageid=" + page.GetPageId().ToString() + "'\" class=\"btn btn-primary rowButton\"/>"; trow.Controls.Add(cell5); //Adding the current row to the Table table1.Rows.Add(trow); } }