using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using CareersOnlineLibrary; using CareersOnlineLibrary.Entity; using CareersOnlineLibrary.Controller; namespace WebApplication1 { public partial class SiteMaster : System.Web.UI.MasterPage { protected void Page_Load(object sender, EventArgs e) { RefreshArticles(); } public void RefreshArticles() { CareersOnlineController controller = new CareersOnlineController(); ArticleCollection articles = new ArticleCollection(); articles = controller.GetTop4Articles(); // loop through each row in the data set and create // the row on the web page in a web table foreach (Article dr in articles) { // add title (use a single column) TableRow tr = new TableRow(); tr.Cells.Add(new TableCell()); // change title color slightly tr.Cells[0].ForeColor = System.Drawing.Color.Navy; tr.Cells[0].Width = 200; // make the text title big and purple tr.Cells[0].Text = "" + dr.Title + ""; this.ArticlesTable.Rows.Add(tr); // add blog in a single column and span 2 columns tr = new TableRow(); tr.Cells.Add(new TableCell()); tr.Cells[0].Width = 200; tr.Cells[0].ColumnSpan = 2; tr.Cells[0].Text = dr.ShortDescription; this.ArticlesTable.Rows.Add(tr); // add user who posted and date (use two columns in the row) tr = new TableRow(); tr.Height = 50; tr.HorizontalAlign = HorizontalAlign.Left; tr.VerticalAlign = VerticalAlign.Middle; tr.Cells.Add(new TableCell()); tr.Cells.Add(new TableCell()); tr.Cells[0].Text = "" + "Read More >>" + ""; DateTime postTime = DateTime.Parse(dr.Date.ToString()); tr.Cells[1].HorizontalAlign = HorizontalAlign.Right; tr.Cells[1].Text = String.Format("{0}", postTime.ToString("MMM dd, yyyy")); this.ArticlesTable.Rows.Add(tr); // add separtor graphic and span 2 columns tr = new TableRow(); tr.Cells.Add(new TableCell()); tr.Cells.Add(new TableCell()); tr.Cells[0].ColumnSpan = 2; this.ArticlesTable.Rows.Add(tr); string imageFile = this.ResolveUrl(@"~\Images\separator.jpg"); System.Web.UI.WebControls.Image separator = new System.Web.UI.WebControls.Image(); separator.ImageUrl = imageFile; separator.Width = 200; separator.Height = 32; separator.Visible = true; tr.Cells[0].Controls.Add(separator); tr.Cells[0].HorizontalAlign = HorizontalAlign.Center; } } protected void latestArticles_RowDataBound(object sender, GridViewRowEventArgs e) { //entire ro is clickable //if (e.Row.RowType == DataControlRowType.DataRow) //{ // // Set the hand mouse cursor for the selected row. // e.Row.Attributes.Add("OnMouseOver", "this.style.cursor = 'hand';"); // // The seelctButton exists for ensuring the selection functionality // // and bind it with the appropriate event hanlder. // LinkButton selectButton = new LinkButton() // { // CommandName = "Select", // Text = e.Row.Cells[0].Text // }; // e.Row.Cells[0].Controls.Add(selectButton); // e.Row.Attributes["OnClick"] = // Page.ClientScript.GetPostBackClientHyperlink(selectButton, ""); //} } protected void latestArticles_RowCreated(object sender, GridViewRowEventArgs e) { // only apply changes if its DataRow if (e.Row.RowType == DataControlRowType.DataRow) { // when mouse is over the row, save original color to new attribute, and change it to highlight yellow color //e.Row.Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#3a4f63'"); e.Row.Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#bfcbd6'"); // when mouse leaves the row, change the bg color to its original value e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalstyle;"); } } } }