News: Sensation!!! Cialis new viagra Symptom tramadol withdrawal Compare viagra price Phentermine ups shipped Tramadol without a prescription Is viagra safe for women Phentermine buy order Buy vicodin online Lamictal Medrol Vicodin info Cheap cialis tablets Advair Podofilox Vicodin prescription Hydrocodone m357 Diet pills phentermine Beconase Compare viagra cialis levitra Hydrocodone addiction Cialis levitra better How quick can you lose weight with phentermine Phentermine with master card Clomipramine Dangers of taking phentermine Female herbal viagra Tramadol sale Ativan Percocet Cheap viagra online Xanax detoxification Cod tramadol Estradiol No perscription tramadol Nabumetone Cerivastatin Paris france cheep viagra Phentermine pharmacy online consultation Alprazolam xanax over night Phentermine $89 Buy Diazepam Lowest phentermine prices Nitroprusside No overnight prescription xanax Diazoxide Viagra generico impotencia Diet phentermine pill Nafcillin Buy Xanax Cheapest phentermine online free shipping Cheap perscription phentermine Buy Adderall Tramadol uses Etanercept Physical symptoms of high blood pressure and xanax Buy phentermine online with pay pal Viagra kaufen Daunorubicin Cheap fioricet Buy discount cialis Ondansetron Geodon Buy cheap phentermine free fedex Buy Propecia Phentermine buy Actonel Viagra dosages Oxytetracycline Phentermine without prescription and energy pill Levivia viagra Cheap phentermine pills Pioglitazone Order phentermine Best online deal for phentermine Alternatives to phentermine Phentermine pill online discount Flonase Capoten Order phentermine overnight Best price for generic viagra Phentermine discount Viagra 6 free sample Minoxidil Erectile dysfunction viagra Famvir Cheap cialis Fact phentermine diet pill Natural viagra type alternatives Ibutilide Viagra anxiety Phentermine 37.5 no prescription Flovent Phentermine 30 mg Ansaid Liotrix Buy viagra cheap Hydrocodone m358 Simvastatin Prescription order viagra online Carisoprodol Acetyldigitoxin Buy phentermine epharmacist Phentermine forum Miglitol Piroxicam Adipex p phentermine vs Filing income tax buy tramadol Vicodin and alcohol Chloramphenicol Cash on delivery for phentermine Xanax withdraw& leukemia symptoms Phentermine diet pill Niacin Prinivil Finasteride Purchase viagra online Buying phentermine online Azithromycin Buy phentermine online no prescription Ambien withdrawal 0 buy by popl powered viagra wordpress Cortisol Get phentermine Cheapest viagra Flavoxate Any drug interaction xanax and cold meds Morphine How long does phentermine stay in your body Viagra and blindness Riboflavin Pyrilamine About xanax Tramadol online pharmacy Soma Buy phentermine prozac Benicar Misoprostol Pink oval pill 17 xanax identification Cheap phentermine without a prescription Phentermine compare prices Buy xanax online without a prescription Minocycline Phentermine reviews M357 vicodin Xanax dosage Phentermine xenical Lethal dose xanax Buy viagra prescription online Synthroid Amiloride Xanax lethal dose Avapro Nicotrol Does viagra woman work Phentermine np with hoodia Epirubicin Buy cheap domain onlineatspacecom xanax Prevacid Cialis for sale Does phentermine interact with hydrocodone Diet phentermine Drug screen xanax Phentermine side affects Epivir Soma online Cialis generic viagra Oxazepam Phentermine India generic viagra Dichloralphenazone Phentermine weight loss Vicodin withdrawal Overnight xanax or alprazolam delivery Lodine Tramadol prescriptions Better than viagra Aerobid Viagra premature Cialis for woman Oxycodone Fluconazole Differin Dilantin Lopid Cheap discount phentermine Fioricet with codeine Generica viagra Does phentermine really work Colace Alternative new viagra Minipress Pfizer viagra online Buy phentermine on line Sertraline Discounted phentermine with no prescription Half life of xanax Physostigmine Buy viagra order viagra 37.5mg phentermine Arthrotec Fenfluramine Levothyroxine Ceftin Cod hydrocodone Order xanax Picture of xanax pill Acitretin Phentermine us pharmacy online consultation Difference between cialis and viagra Phentermine complications Xanax dosages Alternative herbal review viagra Botox Viagra doses Fentanyl Ambien sleeping pill On line doctor phentermine Cause rebound weight gain phentermine Acetophenazine Carbachol Non prescription phentermine Vicodin addiction Mylan xanax Phentermine online Buy Zyrtec Generic price viagra Methenamine Liquid hydrocodone Phentermine ky Allegra Efavirenz Anafranil Viagra commercial Methimazole Lyrica Overnight phentermine no prescription Order phentermine diet pill Phentermine drug interactions Phentermine ionamin canada Oxycontin xanax bars per casettes and lortabs Nitrofurantoin Link buy online viagra info domain Orlistat Cheapest phentermine Viagra 50 mg Biaxin Cheap phentermine free consult How to get a xanax prescription Pharmacy phentermine affiliate Tramadol use Viagra for women Phentermine 37.5 mg no prescription Diltiazem Phentermine c.o.d. Tomorrow Quinine Dangers of phentermine 90 cod count day phentermine Mobic Xanax half life Aldara Stopping xanax Enoxacin Nizoral Asa Cozaar Cheap phentermine prescription Cialis softtabs Tolbutamide Cheap cialis generic Generic cialis softtabs Comparison viagra cialis levitra Zestoretic Adipex loss phentermine weight Albuterol Anxiety disorder xanax Ambien cr Venlafaxine Where to buy viagra Cheapest place to buy phentermine online Blindness viagra Divalproex Phentermine from a mexican pharmacy Hexoprenaline Oxymorphone Phentermine free delivery Information loss phentermine weight Cialis story Viagra overnight Phentermine with free shipping Oxcarbazepine How to inject xanax pills Imdur Xanax urine test Addiction tramadol Tramadol without perscription Streptomycin Levitra vs cialis vs viagra Bulk phentermine Lansoprazole Discount soma Xanax dose Is phentermine dangerous Clonazepam Butalbital Phentermine 37.5mg tablets Doxylamine Natural viagra alternatives Phentermine about withdrawl Buy phentermine online cod Online tramadol Sample viagra Effexor Order fioricet online Viagra testimony Cialis drug interactions Buy phentermine cheap Alprazolam xanax Viagra patent infringement reexam No prescription phentermine Xanax sexual side effects Fexofenadine Ambien Viagrafix corporation 2 mg xanax Phentermine snorting Viagra best buy Phenelzine Nasacort aciphex phentermine actos imitrex Buying vicodin online Fioricet order Hytrin Opium Ciguatoxin Zyban Long term side effects of xanax Cialis tablet Flupenthixol Valium Order viagra visit your doctor online Phentermine message board Alesse Purchase viagra on line Drug prescription tramadol Xanax information Low dose xanax prosexual Phentermine no doctor Tramadol avinza drug interaction Buy phentermine online cash on delivery Phenolphthalein Meridia vs. Phentermine Soma Diet loss phentermine pill weight Zoloft Buy phentermine in canada Generic overnight viagra Troleandomycin Phentermine 30 Advair Dianabol Phentermine side effects dangers Antazoline Phentermine tablets Viagra investigator Adalat Viagra advertisements Bricanyl Tramadol hydrochloride Free sample viagra Side effect of viagra Cheapest online pharmacy phentermine Cardizem Viagra faq Dacarbazine Clemastine Buy vicodin How to get xanax Cialis reviews Xanax federal express Alcohol hydrocodone Dexamethasone Discount meridia Does viagra work for women Terconazole James thompson viagra lawsuit Cheap prices phentermine Indomethacin Amprenavir Phentermine sites that ship cash on delivery Avodart Enoxaparin Generic viagra lowest prices 180 tablet tramadol Mycostatin Viagra picture Soma getting Buy generic viagra Online pharmacy prescription viagra Online viagra prescriptions Fluconazole Viagra recreational Phentermine side effects Tramadol 180 Valerian Phentermine pharmacies online Lansoprazole Viagra uk Skelaxin Paroxetine Viagra patent Xanax bar effects Pantothenic Compare ionamin phentermine Phentermine no perscription needed Viagra results Buy Tylenol First viagra commercial network tv Acetaminophen fioricet Cheapest price viagra Difference between valium and xanax Herbal viagra reviews Clarinex Phentermine low price Fenoprofen Amide pharmaceutical phentermine Ipodate Phentermine perscription Augmentin Diflucan Lipitor Phentermine tablet Phentermine fact Hydrocodone online pharmacy Demeclocycline Cimetidine Atacand Generic cialis price Sulfonamides Viagra sales Hydroxychloroquine Phentermine with no prior prescription Isocarboxazid Phentermine 180 _cialis et levitra Diatrizoate Viagra experiences Ash of soma Alternative viagra Cod overnight tramadol Mechlorethamine Arimidex Side effects of xanax Fosfomycin Discount tramadol Order viagra without prescription Procyclidine Diethylpropion Buy viagra pill Flomax Chlortrimeton Asparaginase Cefazolin Phenprocoumon Phentermine diet medication Phentermine interactions Methadone and xanax Alfentanil Online consultation xanax Fastin Prometrium Nalorphine Tramadol online Free viagra Vicodin dosage Effects of snorting xanax Vicodin es Phentermine 90 day Phenytoin Online pharmacy and phentermine overnight Buy viagra online without prescription Ups cod phentermine Orlistat Lysodren Cheap cialis online Mark martin viagra Cialis viagra Propranolol Viagra cheap prescription Flurbiprofen Grapefruit xanax Phentermine shipped to florida Buy Alprazolam Buspirone Dutasteride Discount viagra online Is there a phentermine shortage Phentermine wholesale Omeprazole Phentermine online without prescription Leuprolide Esmolol Cheap viagra uk Verapamil Lowest prices on phentermine Buying viagra in the uk Buy Codeine Order phentermine online Order vicodin online Buy cialis soft tabs Flonase Phentermine Temazepam Compare cialis levitra viagra Phentermine and atkins diet Tramadol online discount cheap Pictures of mylan xanax Non prescription phentermine Caffeine Dapsone Snorting phentermine Xanax tablet Cytotec Estrace What does phentermine do to your heart Diclofenac Cialis levivia viagra vs vs Phentermine lose weight loss diet pills Xanax drug information Can i take xanax with zocor and procardia Hydrocodone Buy cod pay phentermine Dexbrompheniramine How to stop taking xanax Buy online securely viagra Cialis comparison levitra Generic viagra cialis levivia buy cheap Etretinate Pfizer xanax pills Buy soma Xanax online prescription Fosamax Phentermine forums and chats Inform your doctor medication phentermine dose weight Ambien prescription Mail order viagra Acetaminophen e hydrocodone Buy cialis online Clonazepam Oseltamivir Levofloxacin Phentermine very cheap Diltiazem Ecotrin Cocaine Order phentermine cod online Phentermine diet plan Nefazodone Soma addiction Ethambutol Cialis online 2mg xanax Phentermine from the uk Prinivil Phentermine 6 pm order Drug interaction sibutramine and phentermine Phentermine 37.5 cheap Phentermine ephedrine What is phentermine Phentermine no prescription needed Cialis ineffective Cheap soma Lowest drug price for phentermine Prescription free viagra Urine drug testing of tramadol Xanax online pharmacy Buy Adipex Cardura Imitrex Dangers of taking xanax and neurontin Xanax on line Olsalazine Zithromax Compare levivia and viagra Drug tests for xanax Online pharmacy duromine viagra international Buy viagra canada Home made viagra Generic viagra india Phentermine next day Information on phentermine Viagra by mail Potassium Inderal Buy tramadol without prescription Female viagra uk Abilify Thiotepa Epoprostenol Imiquimod Zoloft and xanax Herbal alternatives to viagra Akane soma Allopurinol Buy phentermine tablet Butorphanol Leucovorin Paromomycin Timolol Buy phentermine online same day delivery Phentermine no rx Cheapest secure delivery cialis uk Order viagra prescription Nadroparin Estrogen Atenolol viagra Lisinopril Viagra sex Drug testing xanax Monopril Viagra lawsuits texas Cheap phentermine 37.5 mg Buy cheap phentermine Delavirdine Butalbital fioricet Mometasone Chlorhexidine Adalat Methazolamide Cheap phentermine diet pills Viagra use in women Order xanax paying cod Viagra joke Leflunomide Oxycontin xanax bars perclesept and lortab Online pharmacies with doctor consultation for viagra Vicodin m360 Compare phentermine price Cialis compared to viagra Saquinavir Colistimethate Xanax overnight delivery Dextrothyroxine Buy cheap domain online outdoors com xanax Bactrim phentermine Buy viagra now online Cheap viagra generic Viagra supplier Phentermine hoodia diet pill Smoking xanax Permax Purchase viagra Cephapirin Amitriptyline Nisoldipine Suicide xanax Abacavir Tramadol hydrochloride tablet Cleocin Claritin Perscription cialis Taking phentermine with antidepressants Discount viagra perscription drug Order ambien Idoxuridine Xanax picture Where to buy viagra on line Killer pain tramadol Tramadol Ethanol Actonel Civiate generic sildenafil viagra Trifluoperazine Tramadol dog 120 tramadol Delivery florida online pharmacy phentermine Phentermine in jonesboro arkansas Octreotide Maker of viagra Soma fm Phentermine without a perscription Viagra cialis Cilexetil Xenical hgh phentermine quit smoking Cheap phentermine no prescription Buy pal pay phentermine using Order phentermine cod Niacin Does xanax show up on drug tests Atenolol Buy discount viagra online Metronidazole 50mg generic viagra $50.00 phentermine Phentermine a159 Cialis generic canada Xanax demerol morphine no prescription needed Phentermine from canada Effects long side term xanax Isoniazid Phentermine sales Levivia vs viagra Carvedilol Viagra without a perscription Apcalis cialis Dihydrotachysterol Discount online viagra Indapamide Estraderm Safe internet shopping generic viagraeng Cialis mexico Cholestyramine Phentermine overnight no perscription Rimantadine Ambien overnight Phentermine online prescriptions Xanax and pregnancy Minipress Cialis co drug eli impotence lilly Tramadol next day Compare cialis levitra Viagra lowest price Buy phentermine online payment method cod accepted Micronase Uk viagra supplier Price for generic viagra Xanax info Weight loss oral hcg and phentermine Herbal phentermine side effects Cheap online phentermine prescription Dimethothiazine Cheap phentermine with online consultation Cialis levitra Cialis uk Viagra cost Order soma online Phentermine fda Phentermine on line without prescription Bosch power tools zio lowest viagra Feldene Tramadol overdose Minocycline Xanax 1mg Imipramine Amitriptyline Cialis discount online Compare phentermine prices On line viagra Phentermine and sibutramine be combined Klonopin vs xanax dosage Cyclobenzaprine Neostigmine Diet medication online phentermine Levivia viagra compared Fioricet addiction Brompheniramine Gentamicin Low dose of viagra Soma san diego Cipro Drug phentermine 37.5 pdr Mephentermine Monopril Isometheptene Free sample herbal viagra Phentermine blue Cialis price comparison Free pack sample viagra Phentermine 37.5 mg diet pill Oxacillin Cafergot Dobutamine Drug interactions with cialis Valium and xanax Cialis vs viagra Xanax valium Nolvadex Phentermine 37 5 But phentermine No prescription cialis Non perscription viagra Buy phentermine Ditropan Uk cheapest viagra Tramadol online cheap Tetrabenazine Clofazimine Pfizer xanax information Addicted to xanax Diet hcl phentermine pill Propofol Trimetrexate Phentermine next day delivery Xanax Mobic Augmentin Phenylpropanolamine Hydrocodone cough syrup Wholesale pfizer viagra Provigil Succinylcholine Buy tramadol cod Cheapest tramadol online Colace Non perscription generic viagra Canada cialis generic Viagra class action Diprolene Adipex Cyclopenthiazide Elidel Tramadol dogs Hydroxyurea Buy phentermine mastercard Cialis effective soft tab treatment Cheap tramadol online Methixene Prilosec Impotence treatment viagra Side effects of phentermine Line prescription viagra Cetirizine Meropenem Takin prozac and xanax Cialis results Pentoxifylline Buy cheap online viagra Phenoxybenzamine Androgel Order viagra online Drug information picture identification tramadol er bvf Oxymetazoline Avapro Discount cialis online Free shipping phentermine Keyword tramadol Mivial valve prolapse viagra Snorting xanax Tramadol sales Xanax long term use Cheap vicodin Buy phentermine online without a prescription Cialis sample Eon phentermine Viagra cialis levitra comparison dosages Non prescription viagra Chromium Mixing cocaine and viagra Fenofibrate Buy cheap generic viagra Nitric oxide viagra Buy online viagra where Tinzaparin Erythromycin Discount fioricet Thyroglobulin Reglan Rabeprazole Teniposide Tramadol cod Herbal viagra Pepcid Online ordering viagra Diet online phentermine pill Phentermine eprescriptions Uk online pharmacy phentermine Lisinopril with viagra Lowest price viagra Picture of xanax pills Viagra in woman Clindamycin Cheapest tramadol Free phentermine Iodine Accutane Where to buy phentermine How viagra works Demerol Buy Effexor Order soma carisoprodol Flexeril Epinephrine Pfizer viagra Buy cialis in uk Thiothixene Cialis generic online Phentermine side effects danger Tramadol 100 mg no prescription Hydrocodone vicodin Etoposide Cidofovir Mexican pharmacy phentermine Meridia weight loss How much weight will you lose on phentermine Herbal viagra alternative review Metaraminol Buy Zyban Vicodin hp Amsterdam holland viagra 100 mg viagra Hydrocodone description Xanax and grapefruit juice How do i stop taking phentermine Loracarbef Phenylbutazone Carteolol Adapalene Phentermine without a prescription Sildenafil Yohimbine Cialis experiences Paroxetine Pepcid Xanax weight loss Fatal dose of xanax Phentermine on sale Tramadol drug Viagra conviaindications Cheapest phentermine diet pill Hydrocodone ap ap Cheapest place to buy phentermine Doxepin Imodium

Archive for the ‘Uncategorized’ Category

Wizard Control Enter Submit Fix

Thursday, May 1st, 2008

Custom ASP.NET Data Pager Control

Monday, April 28th, 2008

Hi, i like many others have been frustrated by the limitations of the DataPager control introducted in v3.5 of the .NET framework.  The main problem is that it is tied in with the DataSource controls.  Whilst i did manage to come up with a solution using the OnPagePropertiesChanging event of the ListView i still couldn’t find a solution to display my pager without using LINQ to SQL or without the Object/Linq DataSource control or without setting the DataSource to the entire record set which is very inefficient.  Therefore I set about coming up with my own solution and have come up with:

namespace Flixon.Web.UI.WebControls
{
public class PagerCommandEventArgs : CommandEventArgs
{
public int StartRowIndex { get; set; }
public int MaximumRows { get; set; }
public PagerCommandEventArgs(int startRowIndex, int maximumRows, CommandEventArgs originalArgs) : base(originalArgs)
{
this.StartRowIndex = startRowIndex;
this.MaximumRows = maximumRows;
}
}
public class Pager : WebControl, INamingContainer
{
public new int Page
{
get
{
if (!string.IsNullOrEmpty(HttpContext.Current.Request.QueryString[this.QueryStringField]))
return Convert.ToInt32(HttpContext.Current.Request.QueryString[this.QueryStringField]);
else
return (int)(this.ViewState["Page"] ?? 1);
}
set { this.ViewState["Page"] = value; }
}
public int PageSize
{
get { return (int)(this.ViewState["PageSize"] ?? 15); }
set { this.ViewState["PageSize"] = value; }
}
public int TotalRowCount
{
get { return (int)(this.ViewState["TotalRowCount"] ?? 0); }
set { this.ViewState["TotalRowCount"] = value; }
}
public int StartRowIndex
{
get { return (this.Page - 1) * this.PageSize; }
}
public int TotalPageCount
{
get { return (int)Math.Ceiling((double)this.TotalRowCount / (double)this.PageSize); }
}
public string Url
{
get { return (string)(this.ViewState["Url"] ?? string.Empty); }
set { this.ViewState["Url"] = value; }
}
public string QueryStringField
{
get { return (string)(this.ViewState["QueryStringField"] ?? string.Empty); }
set { this.ViewState["QueryStringField"] = value; }
}
public bool ShowPreviousNextLinks
{
get { return (bool)(this.ViewState["ShowPreviousNextLinks"] ?? true); }
set { this.ViewState["ShowPreviousNextLinks"] = value; }
}
private static readonly object EventPagerCommand = new object();
public event EventHandler<PagerCommandEventArgs> PagerCommand
{
add
{
this.Events.AddHandler(EventPagerCommand, value);
}
remove
{
this.Events.RemoveHandler(EventPagerCommand, value);
}
}
protected void OnPagerCommand(PagerCommandEventArgs e)
{
EventHandler<PagerCommandEventArgs> handler = (EventHandler<PagerCommandEventArgs>)base.Events[EventPagerCommand];
if (handler != null)
handler(this, e);
}
protected override void CreateChildControls()
{
if (!string.IsNullOrEmpty(this.QueryStringField))
this.CreatePageForQueryString();
else
this.CreatePagerForCommand();
}
private void CreatePageForQueryString()
{
if (this.TotalRowCount > this.PageSize)
this.Controls.Add(new LiteralControl("Page:"));
// Add the previous links
if (this.Page > 1 && this.ShowPreviousNextLinks)
{
this.Controls.Add(new LiteralControl(" "));
this.Controls.Add(this.CreateLink("«", 1));
this.Controls.Add(new LiteralControl(" "));
this.Controls.Add(this.CreateLink("‹", this.Page - 1));
}
// Loop through the pages
if (this.TotalRowCount > this.PageSize)
{
for (int i = (this.Page <= 2 ? 1 : this.Page - 2); i <= (this.Page >= this.TotalPageCount - 2 ? this.TotalPageCount : this.Page + 2); i++)
{
if (this.Page == i)
this.Controls.Add(new LiteralControl(" <u>" + i.ToString() + "</u>"));
else
{
this.Controls.Add(new LiteralControl(" "));
this.Controls.Add(this.CreateLink(i.ToString(), i));
}
}
// Add a link to the last page
if (this.Page < this.TotalPageCount - 2)
{
this.Controls.Add(new LiteralControl(" ... "));
this.Controls.Add(this.CreateLink(this.TotalPageCount.ToString(), this.TotalPageCount));
}
}
// Add the next links
if (this.Page < this.TotalPageCount && this.ShowPreviousNextLinks)
{
this.Controls.Add(new LiteralControl(" "));
this.Controls.Add(this.CreateLink("›", this.Page + 1));
this.Controls.Add(new LiteralControl(" "));
this.Controls.Add(this.CreateLink("»", this.TotalPageCount));
}
}
private void CreatePagerForCommand()
{
if (this.TotalRowCount > this.PageSize)
this.Controls.Add(new LiteralControl("Page:"));
// Add the previous links
if (this.Page > 1 && this.ShowPreviousNextLinks)
{
this.Controls.Add(new LiteralControl(" "));
this.Controls.Add(this.CreateCommand("First", "«", 1));
this.Controls.Add(new LiteralControl(" "));
this.Controls.Add(this.CreateCommand("Previous", "‹", this.Page - 1));
}
// Loop through the pages
if (this.TotalRowCount > this.PageSize)
{
for (int i = (this.Page <= 2 ? 1 : this.Page - 2); i <= (this.Page >= this.TotalPageCount - 2 ? this.TotalPageCount : this.Page + 2); i++)
{
if (this.Page == i)
this.Controls.Add(new LiteralControl(" <u>" + i.ToString() + "</u>"));
else
{
this.Controls.Add(new LiteralControl(" "));
this.Controls.Add(this.CreateCommand("PageChange", i.ToString(), i));
}
}

// Add a link to the last page
if (this.Page < this.TotalPageCount - 2)
{
this.Controls.Add(new LiteralControl(" ... "));
this.Controls.Add(this.CreateCommand("Last", this.TotalPageCount.ToString(), this.TotalPageCount));
}
}

// Add the next links
if (this.Page < this.TotalPageCount && this.ShowPreviousNextLinks)
{
this.Controls.Add(new LiteralControl(" "));
this.Controls.Add(this.CreateCommand("Next", "›", this.Page + 1));
this.Controls.Add(new LiteralControl(" "));
this.Controls.Add(this.CreateCommand("Last", "»", this.TotalPageCount));
}
}

private HyperLink CreateLink(string text, int page)
{
HyperLink control = new HyperLink();
control.Text = text;
control.NavigateUrl = string.Format(this.Url, page);
return control;
}

private LinkButton CreateCommand(string commandName, string text, int page)
{
LinkButton control = new LinkButton();
control.Text = text;
control.CommandName = commandName;
control.CommandArgument = page.ToString();
control.Command += new CommandEventHandler(HandleEvent);
return control;
}

private void HandleEvent(Object sender, CommandEventArgs e)
{
this.Page = Convert.ToInt32(e.CommandArgument);
OnPagerCommand(new PagerCommandEventArgs(this.StartRowIndex, this.PageSize, e));
this.ChildControlsCreated = false;
}
}
}

I’m not going to bore you with exactly what it does but instead show you a couple of examples of how it can be used.

Without a DataSource control

With the new control this is now pretty easy because the TotalRowCount property is not read only. All you have to do is set this property once you have bound your data, ie (GetData is a method which passes in the StartRowIndex and the MaximumRows and returns only the rows you want to display for that page and GetDataCount returns the total number of rows):

protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindData(0);
pager.TotalRowCount = this.GetDataCount();
}
}
protected void BindData(int startRowIndex)
{
lvwItems.DataSource = this.GetData(startRowIndex, pager.PageSize);
lvwItems.DataBind();
}
protected void pager_PagerCommand(Object sender, Flixon.Web.UI.WebControls.PagerCommandEventArgs e)
{
this.BindData(e.StartRowIndex);
}

Then in your aspx file you reference the control in the standard way and put:

<flixon:Pager ID="pager" runat="server" PageSize="15" OnPagerCommand="pager_PagerCommand" />

Without a DataSoruce control (but using the query string to make it seo friendly)

You could modify the above to:

<flixon:Pager ID="pager" runat="server" PageSize="15" QueryStringField="Page" Url="/Default.aspx?Page={0}" />

The PagerCommand event is not necessary if we are using the query string therefore change the code behind file accordingly:

protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
lvwItems.DataSource = this.GetData(pager.StartRowIndex, pager.PageSize);
lvwItems.DataBind();
pager.TotalRowCount = this.GetDataCount();
}
}

Hope this helps.

Creating PDF Documents in ASP.Net

Wednesday, February 27th, 2008

This article will quickly show you how to create pdf documents in ASP.Net.  To get started go to http://itextsharp.sourceforge.net/ and download the iTextSharp library.  Now add the library to your web site.  We can now begin creating a pdf document.

Step 1. Add a new web form to your website.
Step 2. Place the following at the top of your code behind file:

using iTextSharp.text;
using iTextSharp.text.pdf;

Step 3. Finally place the following in the Page_Load event handler:

// Start pdf writer
MemoryStream ms = new MemoryStream();
Document document = new Document();
PdfWriter.GetInstance(document, ms);

// Open the document for writing
document.Open();
// Add a paragraph
Paragraph paragraph = new Paragraph("Hello World");
document.Add(paragraph);

// Close the document
document.Close();

// Output the file
Response.ContentType = "application/pdf";
Response.Clear();
Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
Response.End();

Obviously this is a very basic example but the iTextSharp is not too well documented for ASP.Net (c#) since it was innitially targetted for Java users.

Below is an example of adding an image to your pdf document (replace the path occordingly):

// Add an image
Image logo = Image.GetInstance(Server.MapPath("~/Images/Image.jpg"));
logo.ScaleAbsolute(100, 16);
document.Add(logo);

The next example shows how you can add a new font and some text which uses that font:

// Arial font
BaseFont arial = BaseFont.CreateFont(Server.MapPath("~/Fonts/Arial.ttf"), BaseFont.WINANSI, BaseFont.EMBEDDED);

// Add a paragraph
Paragraph paragraph = new Paragraph();
paragraph.Add(new Chunk("Text", new Font(arial, 14, Font.NORMAL, new Color(0, 125, 195))));
website.Add(new Chunk("More Text", new Font(arial, 14, Font.NORMAL)));
document.Add(paragraph);

Tables are also very simple to do. To add a table you create an instance of the Table class passing the number of columns you wish your table to have and then add it to the document as you have done above:

Table table = new Table(2); // 2 columns
table.AddCell(new Cell("Row 1: Column: 1"));
table.AddCell(new Cell("Row 1: Column: 2"));
table.AddCell(new Cell("Row 2: Column: 1"));
table.AddCell(new Cell("Row 2: Column: 2"));
document.Add(table);

The final example shows how you can add a new page:

// Add a new page
document.NewPage();

I hope this helps you grasp the basics of creating pdf documents in asp.net.

ASP.NET 2 Way Databinding Suggestions/Improvements

Saturday, November 3rd, 2007

Hi, i’ve searched the internet to see if others have documented this problem but i could not find anything so i thought i would post it here.  The problem i have is with 2 way databinding.

First off I must say that I am a big fan of 2 way databinding introduced in asp.net 2.0 but i feel it can be improved.  The main issue i have is that when you using Bind(”name”) the name must be the same both ways.  Imagine i have a DateTime field in my database and i have a calendar to handle the date.  Now i have three drop down lists to handle the time (one each for hour, minute and second).  I would set the SelectedValue for the hour to <%# Bind(”Date”, “{0:HH}”) %> but the name in my update method is DateHour.  The only way i can achieve this is to use Eval and then pass the value on the OnInserting/Updating event handler with the appropriate name.  My solution to this would be to have an additional databinding method called EvalBind (as an example) which you can pass 2 (or 3 if formatting) parameters.  The first would be for the Eval part and the second the Bind part.  Using the example above i could then say <%# EvalBind(”Date”, “DateHour”, “{0:HH}”) %>.
 
However i still have one further issue with the databinding syntax.  I am unable to easily add a default value to a control with 2 way databinding without using the code behind file.  Therefore i have come up with a better solution which would be to add an additional property to the controls called Bind (again as an example) and then i could say <asp:DropDownList ID=”ddlDateHour” runat=”server” SelectedValue=’<%# Eval(”Date”, “{0:HH}”) %>’ Bind=”DateHour”>…</asp:DropDownList> on my edit page and on my insert page i could set the SelectedValue (or Text for a TextBox) to a default value.
 
I know my examples are not brilliant but i have come across these problems many times.  Also both solutions above are backwards compatible.

Pivot Tables with Dynamic Columns

Monday, October 29th, 2007

Hi, Recently i ran into a situation where i had to pivot/rotate a table (change rows to columns).  This makes it very easy to apply filtering and sorting on data which might have seen impossible to do before.  The site i used to help me is found at:

http://www.simple-talk.com/community/blogs/andras/archive/2007/09/14/37265.aspx

I found this a great resource and encourage anyone interested in this field to give it a read.  One particular case i found for doing this is when dealing with dynamic forms.  Imagine i have the following tables:

Attributes:
 - AttributeID
 - AttributeName

Documents:
 - DocumentID
 - Title

DocumentValues
 - AttributeID
 - DocumentID
 - Value

The attributes are basically additional columns to the documents table that i can generate dynamically.  The values for a document’s attributes are then stored in the DocumentValues table.

I can then construct the following sql query (sql server 2005) which will inter-change the rows to columns and give me the benefits mentioned above:

DECLARE @Cols VARCHAR(2000)SELECT @Cols = COALESCE(@Cols + ',[' + AttributeName + ']', '[' + AttributeName + ']')
FROM Attributes
ORDER BY AttributeName

SET @Query = N'SELECT Documents.*, ' + @Cols + ' FROM
(SELECT DocumentValues.DocumentID, DocumentValues.Value, Attributes.AttributeName FROM Attributes INNER JOIN DocumentValues ON Attributes.AttributeID = DocumentValues.AttributeID) p
PIVOT (
MAX([Value])
FOR AttributeName IN (' + @Cols + ')
) AS DocumentValues INNER JOIN
Documents ON DocumentValues.DocumentID = Documents.DocumentID'

Hope this helps.

Object reference not set to an instance of an object

Friday, October 12th, 2007

Hi, this post is more a reminder to myself but for a long time i kept getting the error “Object reference not set to an instance of an object” whilst running my asp.net websites even though the object was not null.  I searched google and found my answer at http://forums.aspfree.com/net-development-11/common-causes-of-object-reference-not-set-to-an-instance-45799.html.  You simply need to run (using the command prompt):

aspnet_regiis -i

Hope this helps.

Adding an empty data template to the repeater control

Wednesday, September 26th, 2007

Hi, i was looking around for an article on how to extend the repeater control to add an empty data template similar to the GridView control.  Here is a link to the the article i found.  However i discovered that it rendered the header and footer, so i set about creating my own one and come up with the following:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ControlLibrary
{
  public class Repeater : System.Web.UI.WebControls.Repeater
  {
  private ITemplate _emptyDataTemplate;
[Browsable(false)]
  [PersistenceMode(PersistenceMode.InnerProperty)]
  public ITemplate EmptyDataTemplate
  {
  get { return _emptyDataTemplate; }
  set { _emptyDataTemplate = value; }
  }
protected override void Render(HtmlTextWriter output)
  {
  // If there is no data then we don't wish to render anything (including the header and the footer)
  if (this.Items.Count == 0)
  {
  // If an empty data template has been provided then display it
  if (this.EmptyDataTemplate != null)
  {
  PlaceHolder phdTemplate = new PlaceHolder();
  this.EmptyDataTemplate.InstantiateIn(phdTemplate);
  phdTemplate.RenderControl(output);
  }
  }
  else
  base.Render(output);
  }
  }
}

Now all you have to do is say:


<%@ Register TagPrefix=”Flixon” Namespace=”ControlLibrary” Assembly=”ControlLibrary” %>
<Flixon:Repeater>
    <ItemTemplate>
          <%# Container.DataItem %>
    </ItemTemplate>
    <EmptyDataTemplate>
         No data returned!
    </EmptyDataTemplate>
</Flixon:Repeater>

on your page and you’re done.

I hope this helps.

Return all results within a category including sub categories

Monday, September 10th, 2007

Hi, i recently ran in to a situation where i had to return every article in my database that was under a particular category (including all articles within the sub categories, sub sub categories and so on).  The Categories table relates a sub category to a category by a ParentID.

At first i went along the lines of a recursive sql statement but this caused problems when there was no articles in one of the top level categories (not an easy problem to spot).  The solution i finally come up with was one i particularly like as it meant i did not have to modify my query much.  I simply add the following function:

CREATE FUNCTION [dbo].[GetCategories]
 (
 @ParentID INT,
 @Output VARCHAR(255)
 )
RETURNS VARCHAR(255)
AS
BEGIN
 IF @Output = ''
 BEGIN
  SET @Output = Convert(VARCHAR(255), @ParentID)
 END
DECLARE @CategoryID INT
 DECLARE c1 CURSOR FOR SELECT CategoryID FROM Categories WHERE ParentID = @ParentID
 OPEN c1
 FETCH NEXT FROM c1 INTO @CategoryID
 WHILE @@FETCH_STATUS = 0
 BEGIN
  SET @Output = @Output + ', ' + Convert(VARCHAR(255), @CategoryID)
  SET @Output = dbo.GetCategories(@CategoryID, @Output)
  FETCH NEXT FROM c1 INTO @CategoryID
 END
 CLOSE c1
 DEALLOCATE c1
RETURN @Output
END

Now i could execute the following query:

SELECT * FROM Articles WHERE CategoryID IN dbo.GetCategories(1, '')

And it would return all the articles where the CategoryID is 1 or the category is a sub of the category specified.

Hope this helps.