Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data.SqlClient;
- public partial class Portfolio : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- string currentID = "";
- SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
- builder.DataSource = @"(local)\sebastianlawe";
- builder.UserID = "sa";
- builder.Password = "dilbert";
- using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
- {
- connection.Open();
- using (SqlCommand command = connection.CreateCommand())
- {
- command.CommandText = @"select SebastianLawe.dbo.PortfolioPage.Id,
- SebastianLawe.dbo.PortfolioPage.Title from SebastianLawe.dbo.PortfolioPage order by [Title]";
- SqlDataReader reader = command.ExecuteReader();
- while (reader.Read())
- {
- object value = reader.GetValue(0);
- Guid id = new Guid(value.ToString());
- string title = reader.GetValue(1) as string;
- HyperLink hyperlink = new HyperLink();
- TableRow row = new TableRow();
- TableCell cell = new TableCell();
- hyperlink.Text = title;
- hyperlink.Font.Size = 15;
- hyperlink.Font.Name = "Verdana";
- hyperlink.Font.Underline = false;
- hyperlink.NavigateUrl = string.Format("portfolio.aspx?Id={0}", id.ToString());
- hyperlink.CssClass = "sideNavbutton";
- cell.Controls.Add(hyperlink);
- row.Controls.Add(cell);
- SidebarTable.Controls.Add(row);
- }
- reader.Close();
- currentID = Request.Params["Id"];
- if(!string.IsNullOrEmpty(currentID)){
- command.CommandText = string.Format(@"select SebastianLawe.dbo.PortfolioPage.Title,
- SebastianLawe.dbo.PortfolioPage.Body from SebastianLawe.dbo.PortfolioPage
- where SebastianLawe.dbo.PortfolioPage.Id = '{0}'", currentID);
- reader = command.ExecuteReader();
- reader.Read();
- string title = reader.GetValue(0) as string;
- string body = Server.HtmlDecode(reader.GetValue(1) as string);
- TitleHeader.Text = title;
- Body.Text = body;
- }
- if (Session["userId"] != null)
- {
- HyperLink hyperlink = new HyperLink();
- hyperlink.NavigateUrl = string.Format("PageEdit.aspx?Id={0}", currentID);
- hyperlink.Text = "Edit";
- Form.Controls.Add(hyperlink);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment