Beanie posted on July 27, 2010 11:46

I've gone a little mad with eBay listings..

After having a tidy up in the garage I have found a load of dive kit that I don't use so i listed it all on eBay.

There's fins, torchs, gauges, regs and more... See my eBay for all of it and more coming as I discover it.


Posted in: Diving  Tags: , , ,

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Beanie posted on July 21, 2010 15:02

    Set oMail=CreateObject("CDO.Message")
        oMail.Subject=
        oMail.From=
        oMail.To=
        oMail.HtmlBody=strBody
        oMail.Send
    set oMail=nothing

Posted in: Development - ASP  Tags:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Beanie posted on April 14, 2010 11:51

For a while I had wanted to add RSS feed for my news sections of my websites, thinking that it had to be relativly straight forward, given it's only XML, I went looking for a simple way to impliment it.

This is how I ened up creating my RSS feeds.

The most important bit is this line in the head section of the page:

<link rel="alternate" href="/feed/" title="website RSS Feed" type="application/rss+xml" />

This tells the browser where the feed is and displays the RSS icon in the address bar of Firefox etc.

The we need to conect to a data source, this is in the web.config file:

<connectionStrings><add name="ConnectionString" connectionString="Data Source=server;Initial Catalog=database;User ID=user;Password=password"providerName="System.Data.SqlClient" /></connectionStrings>

Finally we are ready to create the XML document that will become the RSS feed, using the XmlTextWriter.

   1:  using System;
   2:  using System.Xml;
   3:  using System.Text;
   4:  using System.Collections.Generic;
   5:  using System.Linq;
   6:  using System.Web;
   7:  using System.Web.UI;
   8:  using System.Web.UI.WebControls;
   9:  using System.Data.SqlClient;
  10:  using System.Configuration;
  11:  using System.Data;
  12:   
  13:  public partial class feed_default : System.Web.UI.Page
  14:  {
  15:      protected void Page_Load(object sender, EventArgs e)
  16:      {
  17:          // Clear any previous output from the buffer
  18:          Response.Clear();
  19:          Response.ContentType = "text/xml";
  20:          XmlTextWriter feedWriter = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
  21:          feedWriter.WriteStartDocument();
  22:   
  23:          // These are RSS Tags
  24:          feedWriter.WriteStartElement("rss");
  25:          feedWriter.WriteAttributeString("version", "2.0");
  26:          feedWriter.WriteStartElement("channel");
  27:          feedWriter.WriteElementString("title", "website");
  28:          feedWriter.WriteElementString("link", "http://www.website.com");
  29:          feedWriter.WriteElementString("description", "website News Feed");
  30:          feedWriter.WriteElementString("copyright", "Copyright 2010 website. All rights reserved.");
  31:   
  32:          // Get list of for RSS        
  33:          SqlConnection conn = null;
  34:          conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
  35:          SqlDataReader rdr = null;
  36:          conn.Open();
  37:          SqlCommand cmd = new SqlCommand("selectRssItems", conn);
  38:          cmd.CommandType = CommandType.StoredProcedure;
  39:          // optional search paramters (remove if not required)
  40:          cmd.Parameters.Add(new SqlParameter("@Parameter", "Search"));
  41:          rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
  42:          // Write all Posts in the rss feed
  43:          while (rdr.Read())
  44:          {
  45:              feedWriter.WriteStartElement("item");
  46:              feedWriter.WriteElementString("title", rdr["title"].ToString());
  47:              feedWriter.WriteElementString("description", rdr["description"].ToString());
  48:              feedWriter.WriteElementString("link", "http://www.website.com/news.asp?news=" + rdr["linkID"].ToString());
  49:              feedWriter.WriteElementString("pubDate", rdr["Date"].ToString());
  50:              feedWriter.WriteEndElement();
  51:   
  52:          }         
  53:          // Close all open tags tags
  54:          feedWriter.WriteEndElement();
  55:          feedWriter.WriteEndElement();
  56:          feedWriter.WriteEndDocument();
  57:          feedWriter.Flush();
  58:          feedWriter.Close();
  59:          Response.End();
  60:      }
  61:  }

Posted in: Development - ASP  Tags: , ,

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Beanie posted on December 8, 2009 08:47

I needed to display a list, countries in this case, over two columns. It is relatively simple using record set paging, in its simplest form you count the total rows divide by the number of columns you want then set the page size to the result of that calculation. Then instead of button to scroll through the record set we have a repeater for each page – simples ;-).

ASPX

   1:  <div id="CountryList1" style="float:left; width:40%">
   2:      <asp:Repeater ID="rptCountryList1" runat="server">
   3:          <ItemTemplate>
   4:              <li>
   5:                  <a href="Description.aspx?country=<%# DataBinder.Eval(Container.DataItem, "fldCountryID") %>">
   6:                      <%# DataBinder.Eval(Container.DataItem, "fldCountry") %>
   7:                  </a>
   8:              </li>
   9:          </ItemTemplate>
  10:      </asp:Repeater>
  11:  </div>
  12:   
  13:  <div id="CountryList2" style="float:left; width:40%">
  14:      <asp:Repeater ID="rptCountryList2" runat="server">
  15:          <ItemTemplate>
  16:              <li>
  17:                  <a href="Description.aspx?country=<%# DataBinder.Eval(Container.DataItem, "fldCountryID") %>">
  18:                      <%# DataBinder.Eval(Container.DataItem, "fldCountry") %>
  19:                  </a>
  20:              </li>
  21:          </ItemTemplate>
  22:      </asp:Repeater>
  23:  </div>

 

Code behind

   1:  using System;
   2:  using System.Web;
   3:  using System.Web.Security;
   4:  using System.Web.UI;
   5:  using System.Web.UI.WebControls;
   6:  using System.Web.UI.WebControls.WebParts;
   7:  using System.Web.UI.HtmlControls;
   8:  using System.Data.SqlClient;
   9:  using System.Data;
  10:  using System.Configuration;
  11:   
  12:  public partial class page_name : System.Web.UI.Page
  13:  {
  14:      SqlConnection scon=new  SqlConnection(ConfigurationManager.AppSettings["strConn"]);
  15:      SqlDataAdapter sDA;
  16:      DataSet dsCountryList1;
  17:      DataSet dsCountryList2;
  18:   
  19:      const int intPages = 2;
  20:      int intRows;
  21:      int rowSum;
  22:   
  23:      private void BindData()
  24:      {
  25:          rptCountryList1.DataSource = dsCountryList1;
  26:          rptCountryList1.DataBind();
  27:          rptCountryList2.DataSource = dsCountryList2;
  28:          rptCountryList2.DataBind();
  29:      }
  30:   
  31:      private void readpage(int n)
  32:      {
  33:          SqlCommand cmd = new SqlCommand("SelectCountriesByLetter", scon);
  34:          cmd.CommandType = CommandType.StoredProcedure;
  35:          cmd.Parameters.Add(new SqlParameter("@Product", 10));
  36:          cmd.Parameters.Add(new SqlParameter("@Letter", "%"));
  37:          sDA = new SqlDataAdapter(cmd);
  38:          dsCountryList1 = new DataSet();
  39:          dsCountryList1.Clear();
  40:          sDA.Fill(dsCountryList1, 0, intRows, "tblCountry");
  41:          dsCountryList2 = new DataSet();
  42:          dsCountryList2.Clear();
  43:          sDA.Fill(dsCountryList2,  intRows, intRows, "tblCountry");
  44:      }
  45:   
  46:      protected void Page_Load(object sender, EventArgs e)
  47:      {
  48:          if (!Page.IsPostBack)
  49:          {
  50:              SqlCommand cmd = new SqlCommand("SelectCountriesByLetter", scon);
  51:              cmd.CommandType = CommandType.StoredProcedure;
  52:              cmd.Parameters.Add(new SqlParameter("@Product", 10));
  53:              cmd.Parameters.Add(new SqlParameter("@Letter", "%"));
  54:              sDA = new SqlDataAdapter(cmd); 
  55:              dsCountryList1 = new DataSet();
  56:              try
  57:              {
  58:                  sDA.Fill(dsCountryList1, "tblCountry");
  59:                  rowSum = dsCountryList1.Tables[0].Rows.Count;
  60:              }
  61:              catch (Exception ex)
  62:              {
  63:                  rowSum = 0;
  64:                  return;
  65:              }
  66:              intRows = rowSum / intPages;
  67:              readpage(1);
  68:              BindData();     
  69:          }
  70:      }
  71:  } 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Beanie posted on November 25, 2009 15:31

Ever needed to display more than one value in a bulleted list or dropdown, I did and here is how I ended up getting round it.

Using a normal bulleted list, we leave of the data source and on pageload run loadBulletedLists passing in the list and any variables to filter the stored stocedure used to populate it.

loadBulletedLists takes the recordset and inserts the results into the list, if there are two columns in a row is adds both seperated by a comma, if not it adds the one column.

aspx page

<asp:BulletedList ID="blBulletedList" runat="server" EnableViewState="True"></asp:BulletedList>
aspx.cs page
   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Web;
   5:  using System.Web.UI;
   6:  using System.Web.UI.WebControls;
   7:  using System.Data;
   8:  using System.Data.SqlClient;
   9:  using System.Configuration;
  10:  public partial class Default : System.Web.UI.Page
  11:  {
  12:      protected void Page_Load(object sender, EventArgs e)
  13:      {
  14:          if (!IsPostBack)
  15:          {
  16:              loadBulletedLists(blBulletedList,0);
  17:          }
  18:      }
  19:      protected void loadBulletedLists(object sender, object vParameter)
  20:      {
  21:          BulletedList blList = ((BulletedList)sender);
  22:          blList.Items.Clear();
  23:   
  24:          SqlConnection conn = null;
  25:          conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
  26:          SqlDataReader rdr = null;
  27:          
  28:          conn.Open();
  29:          SqlCommand cmd = new SqlCommand("selectBulletedListItems", conn);
  30:          cmd.CommandType = CommandType.StoredProcedure;
  31:          cmd.Parameters.Add(new SqlParameter("@Parameter", vParameter));
  32:   
  33:          string strColumn1;
  34:          string strColumn2;
  35:          rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
  36:          string strTitle = "";
  37:   
  38:          while (rdr.Read())
  39:          {
  40:              strColumn1 = rdr["fldColumn1"].ToString();
  41:              strColumn2 = rdr["fldColumn2"].ToString();
  42:              if (strColumn1 != "")
  43:              {
  44:                  strTitle = strColumn1;
  45:              }
  46:              if (strColumn2 != "")
  47:              {
  48:                  if (strTitle != "")
  49:                  {
  50:                      strTitle += ", " + strColumn2;
  51:                  }
  52:                  else
  53:                  {
  54:                      strTitle = strColumn2;
  55:                  }
  56:              }
  57:              blList.Items.Add(new ListItem(strTitle));
  58:          }
  59:      }
  60:  }

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Beanie posted on October 27, 2009 18:49
   1:  protected void cboCountry_SelectedIndexChanged(object sender, EventArgs e)
   2:  {        
   3:      cboState.DataBind();
   4:      if (cboState.Items.Count != 0)
   5:      {
   6:          cboState.Visible = true;
   7:          ListItem li = new ListItem("No State", "0");
   8:          cboState.Items.Add(li);
   9:          cboState.SelectedIndex = cboState.Items.IndexOf(cboState.Items.FindByValue("0"));
  10:      }
  11:      else
  12:      {
  13:          cboState.Visible = false;
  14:      }
  15:  }

Posted in: Development , Development - ASP  Tags: , , ,

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Beanie posted on September 17, 2009 13:42

With contract negotiations and rumours happening on a daily basis I thought it might be a good idea to set out which teams have sorted out their rider line up for 2010.

Fiat Yamaha

  • Valentino Rossi
  • Jorge Lorenzo

Repsol Honda Team

  • Daniel Pedrosa
  • Andrea Doviziso

Rizla Suzuki MotoGP

  • Loris Capirossi
  • Alvaro Bautista

Ducati Marlboro Team

  • Nicky Hayden
  • TBC

Monster Yamaha Tech 3

  • Colin Edwards
  • Ben Spies

Pramac Racing (Ducati)

  • TBC
  • TBC

San Carlo Honda Gresini

  • Marco Simoncelli
  • Marco Melandri

LCR Honda MotoGP

  • Randy De Puniet (tbc)
  • Hiroshi Aoyama (Rumour) – Extra Bike

Scot Racing Team MotoGP (Honda)

  • TBC

 

Aspar (Ducati) – New team

  • Héctor Barberá

There are also rumours that Honda may be putting another four bikes on the grid, this may include the one Lucio Cecchinello would like to add to his team.

Riders without a confirmed ride for 2010:

  • James Toseland
  • Chris Vermulen (current seat taken)
  • Alex de Angles (current seat taken)
  • Toni Elias (current seat taken)
  • Casey Stoner
  • Randy De Puniet (LCR keen to keep him)
  • Gabor Talmasi
  • Niccolo Canepa
  • Mika Kallio

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Beanie posted on September 9, 2009 08:56

Ever need to have a dropdown which allows you to have a SelectedIndex that's not in the list?

This is how to write a control to allow you to do this.

   1:  using System;
   2:  using System.Collections;
   3:  using System.Data;
   4:  using System.Web.UI.WebControls;
   5:  using System.Web.UI;
   6:  using System.ComponentModel;
   7:  namespace Controls {
   8:  public class ForgivingDropDownList : DropDownList
   9:      {
  10:          [Category("Behavior"), DefaultValue(true)]
  11:          public bool AllowInvalidSelectedValue
  12:          {
  13:              get { return ViewState["allowInvalid"] != null ? (bool)ViewState["allowInvalid"] : true; }
  14:              set { ViewState["allowInvalid"] = value; }
  15:          }
  16:   
  17:          public override string SelectedValue
  18:          {
  19:              get
  20:              {
  21:                  return base.SelectedValue;
  22:              }
  23:              set
  24:              {
  25:                  if (!AllowInvalidSelectedValue)
  26:                  {
  27:                      base.SelectedValue = value;
  28:                      return;
  29:                  }
  30:                  if (this.Items.Count != 0)
  31:                  {
  32:                      if ((value == null) || (base.DesignMode && (value.Length == 0)))
  33:                      {
  34:                          this.ClearSelection();
  35:                          return;
  36:                      }
  37:                      ListItem item = this.Items.FindByValue(value);
  38:                      if (item == null)
  39:                      {
  40:                          base.SelectedValue = null;
  41:                          return;
  42:                      }
  43:                      base.SelectedValue = value;
  44:                  }
  45:              }
  46:          }
  47:      }
  48:  }

Register it in web.config

   1:  <pages>
   2:         <controls>
   3:          <add tagPrefix="custom"  namespace="Controls" />
   4:      </controls>
   5:  </pages>

Using the dropdown

   1:  <Custom:ForgivingDropDownList  AppendDataBoundItems="true" ID="cbo" runat="server"  DataSourceID="dse" DataValueField="fldID" DataTextField="fld" SelectedValue='<%# bind("fldID") %>' >
   2:  </Custom:ForgivingDropDownList>
   3:                     

Simples ;-)


Posted in: Development  Tags: , , ,

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Beanie posted on September 6, 2009 16:22
Here we take the information from a contact form and email it to the site owner.

 

   1:  protected void btnSend_Click(object sender, EventArgs e)
   2:  {
   3:      if (Page.IsValid)
   4:      {
   5:          string fileName = Server.MapPath("ContactForm.txt");
   6:          string mailBody = string.Empty;
   7:          if (Cache["ContactFormMailBody"] == null)
   8:          {
   9:              mailBody = System.IO.File.ReadAllText(fileName);
  10:              Cache.Insert("ContactFormMailBody", mailBody, new CacheDependency(fileName));
  11:          }
  12:          else
  13:          {
  14:              mailBody = Cache["ContactFormMailBody"].ToString() + "\r\n(File from the cache)";
  15:          }
  16:   
  17:          mailBody = mailBody.Replace("##Name##", txtName.Text);
  18:          mailBody = mailBody.Replace("##Email##", txtEmailAddress.Text);
  19:          mailBody = mailBody.Replace("##HomePhone##", txtPhoneHome.Text);
  20:          mailBody = mailBody.Replace("##BusinessPhone##", txtPhoneBusiness.Text);
  21:          mailBody = mailBody.Replace("##Comments##", txtComments.Text);
  22:   
  23:          MailMessage myMessage = new MailMessage();
  24:          myMessage.Subject = "Response from web site";
  25:          myMessage.Body = mailBody;
  26:   
  27:          myMessage.From = new MailAddress("email@doamin.ext");
  28:          myMessage.To.Add(new MailAddress("web@doamin.ext"));
  29:          lblMessage.Text = "Your message has been sent to us";
  30:          SmtpClient mySmtpClient = new SmtpClient();
  31:          try
  32:          {
  33:              mySmtpClient.Send(myMessage);            
  34:          }
  35:          catch (Exception )
  36:          {
  37:              lblMessage.Text = "An error occurred while sending your e-mail. Please try again.";
  38:          }
  39:   
  40:          lblMessage.Visible = true;
  41:          FormTable.Visible = false;
  42:          System.Threading.Thread.Sleep(5000);
  43:      }
  44:  }
  45:   

The template

    Hi there,
A user has left the following feedback at the site:
Name:               ##Name##
E-mail address:     ##Email##
Home phone:         ##HomePhone##
Business phone:     ##BusinessPhone##
Comments:           ##Comments##

 


Posted in: Development , Development - ASP  Tags: , ,

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Beanie posted on September 6, 2009 16:16

 How to run through all the files within a folder and list them in code.

List files to bulleted list

In this case we find all the files within the current folder except csharp.aspx and populate a bulleted list with them as hyperlinks. The C Sharp index file uses this code to create the sample list.

   1:  using System.IO; 
   2:  using System.Text.RegularExpressions;
   3:   
   4:  protected void Page_Load(object sender, EventArgs e)
   5:  {
   6:      DirectoryInfo di = new DirectoryInfo(MapPath(""));
   7:      FileInfo[] rgFiles = di.GetFiles("*.aspx");        
   8:      string strFile = "";
   9:      foreach (FileInfo fi in rgFiles)
  10:      {
  11:          if (fi.Name.ToLower() != "csharp.aspx")
  12:          {
  13:          strFile = Regex.Replace(fi.Name.ToLower(), ".aspx", "");
  14:          blCsharp.Items.Add(new ListItem(strFile,fi.Name.ToLower()));            
  15:          }
  16:      }
  17:  }

 

List files in dropdown list

In this case we list the number contained within a filename starting with a certain country name. The images/chart fodler contains many charts for different countries each with a numerical identifier As we only need the numberical identifier to store in a database we strip out the rest of the filename and list the charts as [chart #]

   1:  using System.IO;
   2:  using System.Text.RegularExpressions;
   3:   
   4:  protected void Page_Load(object sender, EventArgs e)
   5:  {
   6:      string strCountry = "country name";
   7:      string strChart = "";
   8:      DirectoryInfo di = new DirectoryInfo(MapPath("~/images/charts"));
   9:      FileInfo[] rgFiles = di.GetFiles(strCountry + "*.gif");
  10:      var slSortedList = new SortedList();
  11:   
  12:      foreach (FileInfo fi in rgFiles)
  13:      {
  14:          strChart = Regex.Replace(fi.Name.ToLower(), ".gif", "");
  15:          strChart = Regex.Replace(strChart, strCountry, "");
  16:          slSortedList.Add(strChart,"Chart " + strChart );
  17:      } 
  18:       cboChart.DataSource = slSortedList;
  19:       cboChart.DataTextField = "Value";
  20:       cboChart.DataValueField = "Key";
  21:       cboChart.DataBind();
  22:  }

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Page List

Search Blog

Tag Cloud

Recent Comments

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010 Beanie