SebastianLawe

Untitled

Jun 15th, 2015
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Web;
  4. using System.Web.UI;
  5. using System.Web.UI.WebControls;
  6. using System.Data.SqlClient;
  7.  
  8. public partial class Portfolio : System.Web.UI.Page
  9. {
  10.     protected void Page_Load(object sender, EventArgs e)
  11.     {
  12.         string currentID = "";
  13.         SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
  14.         builder.DataSource = @"(local)\sebastianlawe";
  15.         builder.UserID = "sa";
  16.         builder.Password = "dilbert";
  17.         using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
  18.         {
  19.             connection.Open();
  20.             using (SqlCommand command = connection.CreateCommand())
  21.             {
  22.                 command.CommandText = @"select SebastianLawe.dbo.PortfolioPage.Id,
  23.                SebastianLawe.dbo.PortfolioPage.Title from SebastianLawe.dbo.PortfolioPage order by [Title]";
  24.                 SqlDataReader reader = command.ExecuteReader();
  25.                 while (reader.Read())
  26.                 {
  27.                     object value = reader.GetValue(0);
  28.                     Guid id = new Guid(value.ToString());
  29.                     string title = reader.GetValue(1) as string;
  30.                     HyperLink hyperlink = new HyperLink();
  31.                     TableRow row = new TableRow();
  32.                     TableCell cell = new TableCell();
  33.                     hyperlink.Text = title;
  34.                     hyperlink.Font.Size = 15;
  35.                     hyperlink.Font.Name = "Verdana";
  36.                     hyperlink.Font.Underline = false;
  37.                     hyperlink.NavigateUrl = string.Format("portfolio.aspx?Id={0}", id.ToString());
  38.                     hyperlink.CssClass = "sideNavbutton";
  39.                     cell.Controls.Add(hyperlink);
  40.                     row.Controls.Add(cell);
  41.                     SidebarTable.Controls.Add(row);
  42.                 }
  43.                 reader.Close();
  44.                 currentID = Request.Params["Id"];
  45.                 if(!string.IsNullOrEmpty(currentID)){
  46.                     command.CommandText = string.Format(@"select SebastianLawe.dbo.PortfolioPage.Title,
  47.                    SebastianLawe.dbo.PortfolioPage.Body from SebastianLawe.dbo.PortfolioPage
  48.                    where SebastianLawe.dbo.PortfolioPage.Id = '{0}'", currentID);
  49.                     reader = command.ExecuteReader();
  50.                     reader.Read();
  51.                     string title = reader.GetValue(0) as string;
  52.                     string body = Server.HtmlDecode(reader.GetValue(1) as string);
  53.                     TitleHeader.Text = title;
  54.                     Body.Text = body;
  55.                 }
  56.                 if (Session["userId"] != null)
  57.                 {
  58.                     HyperLink hyperlink = new HyperLink();
  59.                     hyperlink.NavigateUrl = string.Format("PageEdit.aspx?Id={0}", currentID);
  60.                     hyperlink.Text = "Edit";
  61.                     Form.Controls.Add(hyperlink);
  62.                 }
  63.             }
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment