protected void Add_Page(object sender, EventArgs e) { //create connection Dbconnection db = new Dbconnection(); //create a new particular student HttpPage new_HttpPage = new HttpPage(); //set that student data new_HttpPage.SetPageTitle(pagetitle.Text); new_HttpPage.SetPageContent(pagecontent.Text); new_HttpPage.SetPageAuthor(pageauthor.Text); DateTime dateTimeVariable = DateTime.Now; string date = dateTimeVariable.ToString("yyyy-MM-dd H:mm:ss"); new_HttpPage.SetPagePublish_Date(date); //add the student to the database db.AddPage(new_HttpPage); Response.Redirect("ListPages.aspx"); }
protected void Update_Page(object sender, EventArgs e) { //this connection instance is for editing data Dbconnection db = new Dbconnection(); bool valid = true; string Pageid = Request.QueryString["pageid"]; if (!String.IsNullOrEmpty(Pageid)) { HttpPage new_HttpPage = new HttpPage(); //set that Page data new_HttpPage.SetPageTitle(pagetitle.Text); new_HttpPage.SetPageContent(pagecontent.Text); new_HttpPage.SetPageAuthor(pageauthor.Text); //add the Page data to the database try { db.UpdatePage(Int32.Parse(Pageid), new_HttpPage); Response.Redirect("ViewPage.aspx?pageid=" + Pageid); } catch { valid = false; } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { //this connection instance is for showing data Dbconnection db = new Dbconnection(); bool valid = true; string pageid = Request.QueryString["pageid"]; Debug.WriteLine("PageID:" + pageid); if (String.IsNullOrEmpty(pageid)) { valid = false; } //We will attempt to get the record we need if (valid) { HttpPage page_record = db.FindHttpPage(Int32.Parse(pageid)); pagetitle.Text = page_record.GetPageTitle(); pagecontent.Text = page_record.GetPageContent(); pageauthor.Text = page_record.GetPageAuthor(); } } }
//function to delete the page on button click public void Delete_Page(object sender, EventArgs e) { string pageid = Request.QueryString["pageid"]; Dbconnection db = new Dbconnection(); db.DeletePage(pageid); Response.Redirect("ListPages.aspx"); }
void searchpage(Dbconnection db) { string query = "select * from pages order by pageid"; List <Dictionary <string, string> > rs = db.List_Query(query); Dynamic_Menu.InnerHtml = "<ul class=\"nav navbar-nav\">"; foreach (Dictionary <string, string> row in rs) { string pageid = row["pageid"]; string pagetitle = row["pagetitle"]; Dynamic_Menu.InnerHtml += "<li><a href=\"ViewPage.aspx?pageid=" + pageid + "\">" + pagetitle + "</a></li>"; } Dynamic_Menu.InnerHtml += "</ul>"; }
public void ShowPageInfo(Dbconnection db) { bool valid = true; string pageid = Request.QueryString["pageid"]; if (String.IsNullOrEmpty(pageid)) { valid = false; } if (valid) { //finding the page we requested by refering the function FindHttpPage in Dbconnection.cs and gets the records to display on html page HttpPage page_record = db.FindHttpPage(Int32.Parse(pageid)); heading.InnerHtml = page_record.GetPageTitle(); pagecontent.InnerHtml = page_record.GetPageContent(); author.InnerHtml = "Author:" + " " + page_record.GetPageAuthor(); Publishdate.InnerHtml = "Published on" + " " + page_record.GetPagePublish_Date(); } else { valid = false; } }
protected void Page_Load(object sender, EventArgs e) { Dbconnection db = new Dbconnection(); ShowPageInfo(db); }
protected void Page_Load(object sender, EventArgs e) { //empty string to store search key string Search_Key = ""; //empty string to store query string query = ""; if (Page.IsPostBack) { Search_Key = Search_txt.Text.ToString(); //on post back we store keyword entered in textbox to Search_Key } //cheking if string is empty we display all records in th table if (Search_Key == "") { query = "select * from pages"; } //if string is not empty we search for the records which matches that string else { query = "select * from pages where pagetitle like '%" + Search_Key + "%' order by pageid"; } var db = new Dbconnection(); //printing all records one by one in a table row List <Dictionary <String, String> > rs = db.List_Query(query); foreach (Dictionary <String, String> row in rs) { string pageid = row["pageid"]; string pagetitle = row["pagetitle"]; string pagecontent = row["pagebody"]; string pageauthor = row["author"]; string publish_date_time = row["Publish_Date"]; HtmlTableRow trow = new HtmlTableRow(); //1st column HtmlTableCell Cell1 = new HtmlTableCell(); Cell1.InnerText = pageid; trow.Controls.Add(Cell1); //2nd column HtmlTableCell Cell2 = new HtmlTableCell(); Cell2.InnerHtml = "<a href=\"ViewPage.aspx?pageid=" + pageid + "\">" + pagetitle + "</a>"; trow.Controls.Add(Cell2); //3nd column HtmlTableCell Cell3 = new HtmlTableCell(); Cell3.InnerText = pagecontent; trow.Controls.Add(Cell3); //4th column HtmlTableCell Cell4 = new HtmlTableCell(); Cell4.InnerText = pageauthor; trow.Controls.Add(Cell4); //5th column LinkButton EditButton = new LinkButton(); EditButton.Text = "EDIT"; EditButton.ID = "Edit_btn"; EditButton.PostBackUrl = "EditPage.aspx?pageid=" + pageid; HtmlTableCell cell5 = new HtmlTableCell(); cell5.Controls.Add(EditButton); trow.Cells.Add(cell5); ////6th column //LinkButton DeleteButton = new LinkButton(); //DeleteButton.Text = "DELETE"; //DeleteButton.Click += new EventHandler(D); //HtmlTableCell cell6 = new HtmlTableCell(); //cell6.Controls.Add(DeleteButton); //trow.Cells.Add(cell6); Table1.Rows.Add(trow); } }
protected void Page_Load(object sender, EventArgs e) { Dbconnection db = new Dbconnection(); searchpage(db); }