A
Aaron Prohaska
I have a large portion of the code for the two classes below written and
am now running into problems that I don't know how to solve. Below I
have included a description of what each classes responsibilites are and
a little about how they work as well as the code I have for each. There
is quite a lot of code so I'm not including some of the dependent
classes like the FitCalculator class because I don't think it will help
solve the problems.
If someone could please take a look at this and give me some direction
to go in I would really appreciate it as I have hit a wall.
Here is a list of what I can't make work.
How to keep the state of the two FramesViewOptions classes syncronized
so that when a postback occures both classes drop down lists have the
same items selected.
How to architect the two controls to work with ViewState correctly so
the ViewState can correctly recreate the controls on a postback.
The RearTravelList DropDownList control in the FramesViewOptions class
is selecting multiple ListItems on PostBack which is causing an error.
This problem I have tested using the FramesViewOptions class in a page
using its html tag like so:
<ws:FramesViewOptions RidingStyle="FR" Store="Mountain" Material=""
ID="framesViewOptions" Runat="server"/>
When I use the FramesViewOptions class with the tag above in a page then
the RearTravelList DropDownList works as expected. So this problem has
something to do with how this class is used within the FramesView class.
Most of the problems I'm having tend to deal with PostBacks, this is
probably due to my lack of knowledge in programming with asp.net.
Composite Controls:
FramesView:
Displays rows of data from a sql server database by adding a row of data
to a FrameView class which formats the data for display. The FrameView
class is then added to the control collection of FramesView for each row
of data. A FramesViewOptions class is added to the FramesView control
collection above and below the collection of FrameView objects. When a
user changes a DropDownList selection in one of the two
FramesViewOptions instances the other FramesViewOptions instance must be
rendered with the changes on PostBack.
FramesViewOptions
Contains a number of DropDownLists to allow selection of different types
of frames as well as sorting of the current data. When a different type
of frame is selected from one of the lists the FramesView class will
retrieve new data from the database. When the sort list is changed then
the FramesView class gets the data from the Cache object instead of
going back to the database for the sorted data.
// +++++++++++++++++++++++++++++++++++++++++++++++++
// FramesView class
// +++++++++++++++++++++++++++++++++++++++++++++++++
using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.Caching;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using WrenchScience.WSLogic.Data;
using WrenchScience.WSLogic.Utility;
using WrenchScience.WSLogic.WebControls.Events;
using WrenchScience.WSLogic.WebControls.PartViews;
using WrenchScience.WSLogic.WebControls.Utility;
namespace WrenchScience.WSLogic.WebControls.PartViews
{
/// <summary>
/// Summary description for Frames.
/// </summary>
public class FramesView : Abstract.WSLogicControl, INamingContainer,
IFramesViewOptions
{
private PartsDB db = new PartsDB();
private FitCalculator fitCalculator;
private UserFit userFit = new UserFit();
private FramesViewOptions viewOptionsHeader;
private FramesViewOptions viewOptionsFooter;
private DataTable data;
private DataView dataView;
private string material;
private string rearTravel;
private decimal size;
private string sortBy;
private const int iFrameID = 0;
private const int iManufacturer = 1;
private const int iModel = 2;
private const int iPrice = 3;
private const int iGrams = 4;
private const int iAttributeF = 5;
private const int iTopTube = 6;
private const int iTravelMin = 7;
private const int iTravelDefault = 8;
private const int iTravelMax = 9;
private const int iMaterial = 10;
private const int iShortBlurb = 11;
private const int iAesthetic = 12;
public FramesView()
{
//
}
private void GetMaterialFromRequest()
{
if ( Context.Request.QueryString["Material"] != null )
{
string material = Context.Request.QueryString["Material"];
this.Material = material;
}
else if ( Context.Request.Form["Material"] != null )
{
string material = Context.Request.Form["Material"];
this.Material = material;
}
}
protected override void OnInit(EventArgs e)
{
Page.Trace.Write( "FramesView: OnInit." );
// Always call the base method when override
// so what it originally did can still happen
base.OnInit(e);
// Custom logic
if ( !Page.IsPostBack )
{
Page.Trace.Write( "FramesView: set default sort value." );
if ( this.Store == Store.Manufacturer )
this.SortBy = "PModel";
else
this.SortBy = "PManufacturer";
}
}
protected override void CreateChildControls()
{
Page.Trace.Write( "FramesView: Start CreateChildControls." );
Page.Trace.Write( "FramesView: Calculate fitting." );
fitCalculator = new FitCalculator( false, this.Size, ref this.userFit
);
Page.Trace.Write( "FramesView: Create ViewOptionsHeader." );
viewOptionsHeader = new FramesViewOptions();
Page.Trace.Write( "FramesView: Set ViewOptionsHeader properties." );
viewOptionsHeader.Store = this.Store;
viewOptionsHeader.Material = this.Material;
viewOptionsHeader.Manufacturer = this.Manufacturer;
viewOptionsHeader.RearTravel = this.RearTravel;
viewOptionsHeader.RidingStyle = this.RidingStyle;
viewOptionsHeader.Size = this.Size;
viewOptionsHeader.SortBy = this.SortBy;
viewOptionsHeader.ManufacturerChanged += new
FramesViewOptionsEventHandler( this.ManufacturerChanged );
viewOptionsHeader.MaterialChanged += new
FramesViewOptionsEventHandler( this.MaterialChanged );
viewOptionsHeader.RearTravelChanged += new
FramesViewOptionsEventHandler( this.RearTravelChanged );
viewOptionsHeader.SizeChanged += new FramesViewOptionsEventHandler(
this.SizeChanged );
viewOptionsHeader.SortByChanged += new FramesViewOptionsEventHandler(
this.SortByChanged );
Page.Trace.Write( "FramesView: Add ViewOptionsHeader to control
collection." );
this.Controls.Add( viewOptionsHeader );
Page.Trace.Write( "FramesView: Create ViewOptionsFooter." );
viewOptionsFooter = new FramesViewOptions();
viewOptionsFooter.ManufacturerChanged += new
FramesViewOptionsEventHandler( this.ManufacturerChanged );
viewOptionsFooter.MaterialChanged += new
FramesViewOptionsEventHandler( this.MaterialChanged );
viewOptionsFooter.RearTravelChanged += new
FramesViewOptionsEventHandler( this.RearTravelChanged );
viewOptionsFooter.SizeChanged += new FramesViewOptionsEventHandler(
this.SizeChanged );
viewOptionsFooter.SortByChanged += new FramesViewOptionsEventHandler(
this.SortByChanged );
if ( !Page.IsPostBack )
{
this.SetDataSource( true );
this.BuildControlHierarchy();
}
Page.Trace.Write( "FramesView: End CreateChildControls." );
}
private void BuildControlHierarchy()
{
Page.Trace.Write( "FramesView: Start BuildControlHierarchy" );
int frameID = 0;
string manufacturer = "";
string model = "";
decimal price = 0;
decimal grams = 0;
//string attributeF = ""; // AttributeF is not used anymore.
decimal sizeB = 0;
decimal sizeL = 0;
decimal sizeK = 0;
decimal sizeM = 0;
string material = "";
string shortBlurb = "";
string aesthetic = "";
foreach(DataRowView rowView in this.dataView)
{
DataRow frame = rowView.Row;
frameID = Convert.ToInt32(frame[iFrameID]);
if ( !frame.IsNull(iManufacturer) )
manufacturer = Convert.ToString(frame[iManufacturer]);
if ( !frame.IsNull(iModel) )
model = Convert.ToString(frame[iModel]);
if ( !frame.IsNull(iPrice) )
price = Convert.ToDecimal(frame[iPrice]);
if ( !frame.IsNull(iGrams) )
grams = Convert.ToDecimal(frame[iGrams]);
// attributeF = Convert.ToString(frame[5]); // AttributeF is not
used anymore.
if ( !frame.IsNull(iTopTube) )
sizeB = Convert.ToDecimal(frame[iTopTube]);
if ( !frame.IsNull(iTravelMin) )
sizeL = Convert.ToDecimal(frame[iTravelMin]);
if ( !frame.IsNull(iTravelDefault) )
sizeK = Convert.ToDecimal(frame[iTravelDefault]);
if ( !frame.IsNull(iTravelMax) )
sizeM = Convert.ToDecimal(frame[iTravelMax]);
if ( !frame.IsNull(iMaterial) )
material = Convert.ToString(frame[iMaterial]);
if ( !frame.IsNull(iShortBlurb) )
shortBlurb = Convert.ToString(frame[iShortBlurb]);
if ( !frame.IsNull(iAesthetic) )
aesthetic = Convert.ToString(frame[iAesthetic]);
FrameView frameView = new FrameView();
frameView.RidingStyle = (RidingStyle)Enum.Parse(
typeof(RidingStyle), aesthetic );
frameView.FrameID = frameID;
frameView.Manufacturer = manufacturer;
frameView.Model = model;
frameView.Price = price;
frameView.Weight = grams;
frameView.Material = material;
frameView.ShortBlurb = shortBlurb;
this.Controls.Add( frameView );
}
Page.Trace.Write( "FramesView: Set ViewOptionsFooter properties." );
viewOptionsFooter.Store = this.Store;
viewOptionsFooter.Material = this.Material;
viewOptionsFooter.Manufacturer = this.Manufacturer;
viewOptionsFooter.RearTravel = this.RearTravel;
viewOptionsFooter.RidingStyle = this.RidingStyle;
viewOptionsFooter.Size = this.Size;
viewOptionsFooter.SortBy = this.SortBy;
this.Controls.Add( viewOptionsFooter );
Page.Trace.Write( "FramesView: End BuildControlHierarchy" );
}
private void SetDataSource(bool useDataSource)
{
Page.Trace.Write( "FramesView: SetDataSource(" +
useDataSource.ToString() + ")" );
if ( HttpContext.Current.Cache["framesData"] == null || useDataSource
== true )
{
Page.Trace.Write( "FramesView: Get new data from database." );
switch(this.Store)
{
case Store.Road:
this.data = db.GetFramesForRoad( this.Material,
userFit.FrameInseam, this.SortBy, userFit.Weight, userFit.Height );
break;
case Store.Mountain:
this.data = db.GetFramesForMountain( this.RidingStyle.ToString(),
userFit.FrameInseamMin, userFit.FrameInseamMax, userFit.Weight,
this.SortBy );
break;
case Store.Cyclocross:
this.data = db.GetFramesForCyclocross( userFit.FrameInseamMin,
userFit.FrameInseamMax, this.SortBy );
break;
case Store.Manufacturer:
this.data = db.GetFramesForManufacturer( this.Manufacturer,
userFit.FrameInseam, this.SortBy, userFit.Weight, userFit.Height );
break;
}
this.dataView = this.data.DefaultView;
HttpContext.Current.Cache.Insert( "framesData", this.data, null,
DateTime.Now.AddMinutes(1), TimeSpan.Zero );
}
else
{
Page.Trace.Write( "FramesView: Get data from Cache." );
this.data = (DataTable)HttpContext.Current.Cache["framesData"];
this.dataView = this.data.DefaultView;
}
}
private void SortData()
{
switch(this.SortBy)
{
case "PModel":
this.dataView.Sort = "PModel";
break;
case "PGrams":
this.dataView.Sort = "PGrams";
break;
case "PPrice":
this.dataView.Sort = "PPrice";
break;
default:
this.dataView.Sort = "PModel";
break;
}
}
private void ManufacturerChanged(object sender,
FramesViewOptionsEventArgs e)
{
Page.Trace.Write( "FramesView: ManufacturerChanged." );
this.Manufacturer = e.Manufacturer;
this.SortBy = e.SortBy;
this.SetDataSource( true );
this.BuildControlHierarchy();
}
private void MaterialChanged(object sender, FramesViewOptionsEventArgs
e)
{
Page.Trace.Write( "FramesView: MaterialChanged." );
this.Material = e.Material;
this.SortBy = e.SortBy;
this.SetDataSource( true );
this.BuildControlHierarchy();
}
private void RearTravelChanged(object sender,
FramesViewOptionsEventArgs e)
{
Page.Trace.Write( "FramesView: RearTravelChanged." );
this.RidingStyle = (RidingStyle)Enum.Parse( typeof(RidingStyle),
e.RearTravel );
this.SortBy = e.SortBy;
this.SetDataSource( true );
this.BuildControlHierarchy();
}
private void SizeChanged(object sender, FramesViewOptionsEventArgs e)
{
Page.Trace.Write( "FramesView: SizeChanged." );
this.Size = e.Size;
this.SortBy = e.SortBy;
fitCalculator = new FitCalculator( true, this.Size, ref userFit );
this.SetDataSource( true );
this.BuildControlHierarchy();
}
private void SortByChanged(object sender, FramesViewOptionsEventArgs
e)
{
Page.Trace.Write( "FramesView: SortByChanged." );
this.SortBy = e.SortBy;
this.SetDataSource( false );
this.SortData();
this.BuildControlHierarchy();
}
#region Register Client Scripts
public void RegisterScriptForLinkedList(string arrayName, DataTable
data)
{
const int iParentCol = 0;
const int iChildCol = 1;
string parentVal = "";
string prevParentVal = "";
strin nextParentVal = "";
string newLine = TextUtil.CRLF;
char doubleQoute = TextUtil.DoubleQoute;
char comma = TextUtil.Comma;
char space = TextUtil.Space;
string commaVal = "";
string spaceVal = "";
StringBuilder sb = new StringBuilder();
sb.Append( "<script language=" + doubleQoute + "javascript" +
doubleQoute + ">" + newLine );
sb.Append( "var NS4 = (navigator.appName == " + doubleQoute +
"Netscape" + doubleQoute + " && parseInt(navigator.appVersion) < 5);" +
newLine );
sb.Append( "var NSX = (navigator.appName == " + doubleQoute +
"Netscape" + doubleQoute + ");" + newLine );
sb.Append( "var IE4 = (document.all) ? true : false;" + newLine );
sb.Append( newLine );
sb.Append( "var " + arrayName + " = new Array();" + newLine );
//
int rowCount = data.Rows.Count;
for(int iRow = 0; iRow < rowCount; iRow++)
{
DataRow row = data.Rows[iRow];
// get value of first column in row.
parentVal = row[iParentCol].ToString();
// Set previous parent to current row value.
prevParentVal = parentVal;
// Create new array index and values.
sb.Append( arrayName + "[" + iRow + "] = new Array(" );
// Loop through child values and add to this array.
while( parentVal == prevParentVal && iRow <= rowCount)
{
if ( iRow <= rowCount - 1)
nextParentVal = row[iParentCol + 1].ToString();
else
nextParentVal = "";
if ( !((parentVal != prevParentVal) || (parentVal != nextParentVal)
|| (nextParentVal == string.Empty)) )
{
commaVal = comma.ToString();
spaceVal = space.ToString();
}
//
string childVal = row[iChildCol].ToString().Replace( "'", "+" );
sb.Append( doubleQoute + childVal + doubleQoute + commaVal +
spaceVal );
// If no more child values exist exit loop.
if ( parentVal != nextParentVal )
break;
else
iRow += 1;
} // end while
sb.Append( "};" + newLine );
} // end for
//
sb.Append( "</script>" + newLine );
string script = sb.ToString();
Page.RegisterStartupScript( arrayName, script );
}
#endregion
public string Material
{
get { return this.material; }
set { this.material = value; }
}
public string RearTravel
{
get { return this.rearTravel; }
set { this.rearTravel = value; }
}
public decimal Size
{
get { return this.size; }
set { this.size = value; }
}
public string SortBy
{
get { return this.sortBy; }
set { this.sortBy = value; }
}
} // class
} // namespace
// +++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++
// FramesViewOptions class
// +++++++++++++++++++++++++++++++++++++++++++++++++
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using WrenchScience.WSLogic.Data;
using WrenchScience.WSLogic.Utility;
using WrenchScience.WSLogic.WebControls.Events;
using WrenchScience.WSLogic.WebControls.Lists;
namespace WrenchScience.WSLogic.WebControls.PartViews
{
/// <summary>
/// Summary description for FramesNavigator.
/// </summary>
public class FramesViewOptions : Abstract.SkinnedControl,
IFramesViewOptions
{
private PartsDB db = new PartsDB();
private string skinVirtualPath =
"/Skins/Navigation/FramesNavigator.ascx";
private string material;
private string rearTravel;
private decimal size;
private string sortBy;
private Panel materialPanel;
private Panel sizePanel;
private Panel rearTravelPanel;
private Panel manufacturerPanel;
private DropDownList materialList;
private FrameSizeList sizeList;
private DropDownList rearTravelList;
private DropDownList manufacturerList;
private DropDownList sortByList;
public event FramesViewOptionsEventHandler ManufacturerChanged;
public event FramesViewOptionsEventHandler MaterialChanged;
public event FramesViewOptionsEventHandler RearTravelChanged;
public event FramesViewOptionsEventHandler SizeChanged;
public event FramesViewOptionsEventHandler SortByChanged;
protected virtual void
OnManufacturerChanged(FramesViewOptionsEventArgs e)
{
if ( ManufacturerChanged != null )
ManufacturerChanged( this, e );
}
protected virtual void OnMaterialChanged(FramesViewOptionsEventArgs e)
{
if ( MaterialChanged != null )
MaterialChanged( this, e );
}
protected virtual void OnRearTravelChanged(FramesViewOptionsEventArgs
e)
{
if ( RearTravelChanged != null )
RearTravelChanged( this, e );
}
protected virtual void OnSizeChanged(FramesViewOptionsEventArgs e)
{
if ( SizeChanged != null )
SizeChanged( this, e );
}
protected virtual void OnSortByChanged(FramesViewOptionsEventArgs e)
{
if ( SortByChanged != null )
SortByChanged( this, e );
}
public FramesViewOptions()
{
if ( this.SkinVirtualPath == null )
this.SkinVirtualPath = this.skinVirtualPath;
}
protected override void InitializeSkin(Control skin)
{
Page.Trace.Write( "FramesViewOptions: Start InitializeSkin." );
this.manufacturerList =
(DropDownList)skin.FindControl("manufacturerList");
this.manufacturerPanel =
(Panel)skin.FindControl("manufacturerPanel");
this.materialList = (DropDownList)skin.FindControl("materialList");
this.materialPanel = (Panel)skin.FindControl("materialPanel");
this.rearTravelList =
(DropDownList)skin.FindControl("rearTravelList");
this.rearTravelPanel = (Panel)skin.FindControl("rearTravelPanel");
this.sizeList = (FrameSizeList)skin.FindControl("sizeList");
this.sizePanel = (Panel)skin.FindControl("sizePanel");
this.sortByList = (DropDownList)skin.FindControl("sortByList");
if ( this.manufacturerList != null && this.manufacturerPanel != null
)
{
if ( this.Store == Store.Manufacturer )
{
Page.Trace.Write( "FramesViewOptions: Set manufacturerList
properties." );
this.manufacturerList.AutoPostBack = true;
this.manufacturerList.SelectedIndexChanged += new EventHandler(
this.SelectedManufacturerChanged );
if ( !Page.IsPostBack )
this.BuildManufacturerList();
}
else
{
this.manufacturerList.Visible = false;
this.manufacturerPanel.Visible = false;
}
}
if ( this.materialList != null && this.materialPanel != null )
{
if ( this.Store == Store.Road )
{
Page.Trace.Write( "FramesViewOptions: Set materialList properties."
);
this.materialList.AutoPostBack = true;
this.materialList.SelectedIndexChanged += new EventHandler(
this.SelectedMaterialChanged );
if ( !Page.IsPostBack )
this.BuildMaterialList();
}
else
{
this.materialList.Visible = false;
this.materialPanel.Visible = false;
}
}
if ( this.rearTravelList != null && this.rearTravelPanel != null )
{
if ( (this.Store == Store.Mountain) && (this.RidingStyle ==
RidingStyle.XC || this.RidingStyle == RidingStyle.FR || this.RidingStyle
== RidingStyle.FS) )
{
Page.Trace.Write( "FramesViewOptions: Set rearTravelList
properties." );
this.rearTravelList.AutoPostBack = true;
this.rearTravelList.SelectedIndexChanged += new EventHandler(
this.SelectedRearTravelChanged );
if ( !Page.IsPostBack )
this.BuildRearTravelList();
}
else
{
this.rearTravelList.Visible = false;
this.rearTravelPanel.Visible = false;
}
Page.Trace.Write( "FramesViewOptions: End InitializeSkin." );
}
if ( this.sizeList != null && this.sizePanel != null )
{
if ( this.Store == Store.Mountain || this.Store == Store.Road ||
this.Store == Store.Cyclocross )
{
Page.Trace.Write( "FramesViewOptions: Set sizeList properties." );
this.sizeList.AutoPostBack = true;
this.sizeList.SelectedIndexChanged += new EventHandler(
this.SelectedSizeChanged );
if ( !Page.IsPostBack )
{
Page.Trace.Write( "FramesViewOptions: BuildSizeList." );
this.sizeList.Material = this.Material;
this.sizeList.RidingStyle = this.RidingStyle;
this.sizeList.Size = this.Size;
}
}
else
{
this.sizeList.Visible = false;
this.sizePanel.Visible = false;
}
}
if ( this.sortByList != null )
{
Page.Trace.Write( "FramesViewOptions: Set sortByList properties." );
this.sortByList.AutoPostBack = true;
this.sortByList.SelectedIndexChanged += new EventHandler(
this.SelectedSortByChanged );
if ( !Page.IsPostBack )
this.BuildSortByList();
}
}
private void BuildManufacturerList()
{
Page.Trace.Write( "FramesViewOptions: BuildManufacturerList." );
DataTable data = db.GetManufacturersForPartType( "Frame", 'A', 'Z' );
this.manufacturerList.DataTextField = "PMManufacturer";
this.manufacturerList.DataValueField = "PMManufacturer";
this.manufacturerList.DataSource = data;
this.manufacturerList.DataBind();
this.SetSelectedItem( this.manufacturerList, this.Manufacturer );
}
private void BuildMaterialList()
{
Page.Trace.Write( "FramesViewOptions: BuildMaterialList." );
DataTable data = db.GetFrameMaterials( -1, -1, -1 );
this.materialList.DataTextField = "PMaterial";
this.materialList.DataValueField = "PMaterial";
this.materialList.DataSource = data;
this.materialList.DataBind();
this.SetSelectedItem( this.materialList, this.Material );
}
private void BuildRearTravelList()
{
Page.Trace.Write( "FramesViewOptions: BuildRearTravelList." );
this.rearTravelList.Items.Add( new ListItem( "X Country 2.25-4.49in",
RidingStyle.XC.ToString() ) );
this.rearTravelList.Items.Add( new ListItem( "Free Ride 4.5-6in",
RidingStyle.FR.ToString() ) );
this.SetSelectedItem( this.rearTravelList,
this.RidingStyle.ToString() );
}
private void BuildSortByList()
{
Page.Trace.Write( "FramesViewOptions: BuildSortByList." );
if ( this.Store == Store.Manufacturer )
this.sortByList.Items.Add( new ListItem( "model", "PModel" ) );
else
this.sortByList.Items.Add( new ListItem( "manufacturer",
"PManufacturer" ) );
this.sortByList.Items.Add( new ListItem( "grams", "PGrams" ) );
this.sortByList.Items.Add( new ListItem( "price", "PPrice" ) );
this.SetSelectedItem( this.sortByList, this.SortBy );
}
private void SetSelectedItem(ListControl list, string textValue)
{
list.ClearSelection();
ListItem item = list.Items.FindByValue( textValue );
if ( item != null )
item.Selected = true;
}
private void SelectedManufacturerChanged(object sender, EventArgs e)
{
Page.Trace.Write( "FramesViewOptions: SelectedManufacturerChanged
Event Fired." );
string selectedManufacturer = string.Empty;
string selectedSortBy = string.Empty;
selectedManufacturer = this.manufacturerList.SelectedValue;
selectedSortBy = this.sortByList.SelectedValue;
OnManufacturerChanged( new FramesViewOptionsEventArgs(
selectedManufacturer, "", "", 0, selectedSortBy ) );
}
private void SelectedMaterialChanged(object sender, EventArgs e)
{
Page.Trace.Write( "FramesViewOptions: SelectedMaterialChanged Event
Fired." );
string selectedMaterial = string.Empty;
string selectedSortBy = string.Empty;
selectedMaterial = this.materialList.SelectedValue;
selectedSortBy = this.sortByList.SelectedValue;
OnMaterialChanged( new FramesViewOptionsEventArgs( "",
selectedMaterial, "", 0, selectedSortBy ) );
}
private void SelectedRearTravelChanged(object sender, EventArgs e)
{
Page.Trace.Write( "FramesViewOptions: SelectedRearTravelChanged Event
Fired." );
string selectedRearTravel = string.Empty;
string selectedSortBy = string.Empty;
selectedRearTravel = this.rearTravelList.SelectedValue;
selectedSortBy = this.sortByList.SelectedValue;
OnRearTravelChanged( new FramesViewOptionsEventArgs( "", "",
selectedRearTravel, 0, selectedSortBy ) );
}
private void SelectedSizeChanged(object sender, EventArgs e)
{
Page.Trace.Write( "FramesViewOptions: SelectedSizeChanged Event
Fired." );
string selectedSize = string.Empty;
decimal size;
string selectedSortBy = string.Empty;
selectedSize = this.sizeList.SelectedValue;
size = Convert.ToDecimal(selectedSize);
selectedSortBy = this.sortByList.SelectedValue;
OnSizeChanged( new FramesViewOptionsEventArgs( "", "", "", size,
selectedSortBy ) );
}
private void SelectedSortByChanged(object sender, EventArgs e)
{
Page.Trace.Write( "FramesViewOptions: SelectedSortByChanged Event
Fired." );
string selectedSortBy = string.Empty;
selectedSortBy = this.sortByList.SelectedValue;
OnSortByChanged( new FramesViewOptionsEventArgs( "", "", "", 0,
selectedSortBy ) );
}
public string Material
{
get { return this.material; }
set { this.material = value; }
}
public string RearTravel
{
get { return this.rearTravel; }
set { this.rearTravel = value; }
}
public decimal Size
{
get { return this.size; }
set { this.size = value; }
}
public string SortBy
{
get { return this.sortBy; }
set { this.sortBy = value; }
}
} // class
} // namespace
// +++++++++++++++++++++++++++++++++++++++++++++++++
am now running into problems that I don't know how to solve. Below I
have included a description of what each classes responsibilites are and
a little about how they work as well as the code I have for each. There
is quite a lot of code so I'm not including some of the dependent
classes like the FitCalculator class because I don't think it will help
solve the problems.
If someone could please take a look at this and give me some direction
to go in I would really appreciate it as I have hit a wall.
Here is a list of what I can't make work.
How to keep the state of the two FramesViewOptions classes syncronized
so that when a postback occures both classes drop down lists have the
same items selected.
How to architect the two controls to work with ViewState correctly so
the ViewState can correctly recreate the controls on a postback.
The RearTravelList DropDownList control in the FramesViewOptions class
is selecting multiple ListItems on PostBack which is causing an error.
This problem I have tested using the FramesViewOptions class in a page
using its html tag like so:
<ws:FramesViewOptions RidingStyle="FR" Store="Mountain" Material=""
ID="framesViewOptions" Runat="server"/>
When I use the FramesViewOptions class with the tag above in a page then
the RearTravelList DropDownList works as expected. So this problem has
something to do with how this class is used within the FramesView class.
Most of the problems I'm having tend to deal with PostBacks, this is
probably due to my lack of knowledge in programming with asp.net.
Composite Controls:
FramesView:
Displays rows of data from a sql server database by adding a row of data
to a FrameView class which formats the data for display. The FrameView
class is then added to the control collection of FramesView for each row
of data. A FramesViewOptions class is added to the FramesView control
collection above and below the collection of FrameView objects. When a
user changes a DropDownList selection in one of the two
FramesViewOptions instances the other FramesViewOptions instance must be
rendered with the changes on PostBack.
FramesViewOptions
Contains a number of DropDownLists to allow selection of different types
of frames as well as sorting of the current data. When a different type
of frame is selected from one of the lists the FramesView class will
retrieve new data from the database. When the sort list is changed then
the FramesView class gets the data from the Cache object instead of
going back to the database for the sorted data.
// +++++++++++++++++++++++++++++++++++++++++++++++++
// FramesView class
// +++++++++++++++++++++++++++++++++++++++++++++++++
using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.Caching;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using WrenchScience.WSLogic.Data;
using WrenchScience.WSLogic.Utility;
using WrenchScience.WSLogic.WebControls.Events;
using WrenchScience.WSLogic.WebControls.PartViews;
using WrenchScience.WSLogic.WebControls.Utility;
namespace WrenchScience.WSLogic.WebControls.PartViews
{
/// <summary>
/// Summary description for Frames.
/// </summary>
public class FramesView : Abstract.WSLogicControl, INamingContainer,
IFramesViewOptions
{
private PartsDB db = new PartsDB();
private FitCalculator fitCalculator;
private UserFit userFit = new UserFit();
private FramesViewOptions viewOptionsHeader;
private FramesViewOptions viewOptionsFooter;
private DataTable data;
private DataView dataView;
private string material;
private string rearTravel;
private decimal size;
private string sortBy;
private const int iFrameID = 0;
private const int iManufacturer = 1;
private const int iModel = 2;
private const int iPrice = 3;
private const int iGrams = 4;
private const int iAttributeF = 5;
private const int iTopTube = 6;
private const int iTravelMin = 7;
private const int iTravelDefault = 8;
private const int iTravelMax = 9;
private const int iMaterial = 10;
private const int iShortBlurb = 11;
private const int iAesthetic = 12;
public FramesView()
{
//
}
private void GetMaterialFromRequest()
{
if ( Context.Request.QueryString["Material"] != null )
{
string material = Context.Request.QueryString["Material"];
this.Material = material;
}
else if ( Context.Request.Form["Material"] != null )
{
string material = Context.Request.Form["Material"];
this.Material = material;
}
}
protected override void OnInit(EventArgs e)
{
Page.Trace.Write( "FramesView: OnInit." );
// Always call the base method when override
// so what it originally did can still happen
base.OnInit(e);
// Custom logic
if ( !Page.IsPostBack )
{
Page.Trace.Write( "FramesView: set default sort value." );
if ( this.Store == Store.Manufacturer )
this.SortBy = "PModel";
else
this.SortBy = "PManufacturer";
}
}
protected override void CreateChildControls()
{
Page.Trace.Write( "FramesView: Start CreateChildControls." );
Page.Trace.Write( "FramesView: Calculate fitting." );
fitCalculator = new FitCalculator( false, this.Size, ref this.userFit
);
Page.Trace.Write( "FramesView: Create ViewOptionsHeader." );
viewOptionsHeader = new FramesViewOptions();
Page.Trace.Write( "FramesView: Set ViewOptionsHeader properties." );
viewOptionsHeader.Store = this.Store;
viewOptionsHeader.Material = this.Material;
viewOptionsHeader.Manufacturer = this.Manufacturer;
viewOptionsHeader.RearTravel = this.RearTravel;
viewOptionsHeader.RidingStyle = this.RidingStyle;
viewOptionsHeader.Size = this.Size;
viewOptionsHeader.SortBy = this.SortBy;
viewOptionsHeader.ManufacturerChanged += new
FramesViewOptionsEventHandler( this.ManufacturerChanged );
viewOptionsHeader.MaterialChanged += new
FramesViewOptionsEventHandler( this.MaterialChanged );
viewOptionsHeader.RearTravelChanged += new
FramesViewOptionsEventHandler( this.RearTravelChanged );
viewOptionsHeader.SizeChanged += new FramesViewOptionsEventHandler(
this.SizeChanged );
viewOptionsHeader.SortByChanged += new FramesViewOptionsEventHandler(
this.SortByChanged );
Page.Trace.Write( "FramesView: Add ViewOptionsHeader to control
collection." );
this.Controls.Add( viewOptionsHeader );
Page.Trace.Write( "FramesView: Create ViewOptionsFooter." );
viewOptionsFooter = new FramesViewOptions();
viewOptionsFooter.ManufacturerChanged += new
FramesViewOptionsEventHandler( this.ManufacturerChanged );
viewOptionsFooter.MaterialChanged += new
FramesViewOptionsEventHandler( this.MaterialChanged );
viewOptionsFooter.RearTravelChanged += new
FramesViewOptionsEventHandler( this.RearTravelChanged );
viewOptionsFooter.SizeChanged += new FramesViewOptionsEventHandler(
this.SizeChanged );
viewOptionsFooter.SortByChanged += new FramesViewOptionsEventHandler(
this.SortByChanged );
if ( !Page.IsPostBack )
{
this.SetDataSource( true );
this.BuildControlHierarchy();
}
Page.Trace.Write( "FramesView: End CreateChildControls." );
}
private void BuildControlHierarchy()
{
Page.Trace.Write( "FramesView: Start BuildControlHierarchy" );
int frameID = 0;
string manufacturer = "";
string model = "";
decimal price = 0;
decimal grams = 0;
//string attributeF = ""; // AttributeF is not used anymore.
decimal sizeB = 0;
decimal sizeL = 0;
decimal sizeK = 0;
decimal sizeM = 0;
string material = "";
string shortBlurb = "";
string aesthetic = "";
foreach(DataRowView rowView in this.dataView)
{
DataRow frame = rowView.Row;
frameID = Convert.ToInt32(frame[iFrameID]);
if ( !frame.IsNull(iManufacturer) )
manufacturer = Convert.ToString(frame[iManufacturer]);
if ( !frame.IsNull(iModel) )
model = Convert.ToString(frame[iModel]);
if ( !frame.IsNull(iPrice) )
price = Convert.ToDecimal(frame[iPrice]);
if ( !frame.IsNull(iGrams) )
grams = Convert.ToDecimal(frame[iGrams]);
// attributeF = Convert.ToString(frame[5]); // AttributeF is not
used anymore.
if ( !frame.IsNull(iTopTube) )
sizeB = Convert.ToDecimal(frame[iTopTube]);
if ( !frame.IsNull(iTravelMin) )
sizeL = Convert.ToDecimal(frame[iTravelMin]);
if ( !frame.IsNull(iTravelDefault) )
sizeK = Convert.ToDecimal(frame[iTravelDefault]);
if ( !frame.IsNull(iTravelMax) )
sizeM = Convert.ToDecimal(frame[iTravelMax]);
if ( !frame.IsNull(iMaterial) )
material = Convert.ToString(frame[iMaterial]);
if ( !frame.IsNull(iShortBlurb) )
shortBlurb = Convert.ToString(frame[iShortBlurb]);
if ( !frame.IsNull(iAesthetic) )
aesthetic = Convert.ToString(frame[iAesthetic]);
FrameView frameView = new FrameView();
frameView.RidingStyle = (RidingStyle)Enum.Parse(
typeof(RidingStyle), aesthetic );
frameView.FrameID = frameID;
frameView.Manufacturer = manufacturer;
frameView.Model = model;
frameView.Price = price;
frameView.Weight = grams;
frameView.Material = material;
frameView.ShortBlurb = shortBlurb;
this.Controls.Add( frameView );
}
Page.Trace.Write( "FramesView: Set ViewOptionsFooter properties." );
viewOptionsFooter.Store = this.Store;
viewOptionsFooter.Material = this.Material;
viewOptionsFooter.Manufacturer = this.Manufacturer;
viewOptionsFooter.RearTravel = this.RearTravel;
viewOptionsFooter.RidingStyle = this.RidingStyle;
viewOptionsFooter.Size = this.Size;
viewOptionsFooter.SortBy = this.SortBy;
this.Controls.Add( viewOptionsFooter );
Page.Trace.Write( "FramesView: End BuildControlHierarchy" );
}
private void SetDataSource(bool useDataSource)
{
Page.Trace.Write( "FramesView: SetDataSource(" +
useDataSource.ToString() + ")" );
if ( HttpContext.Current.Cache["framesData"] == null || useDataSource
== true )
{
Page.Trace.Write( "FramesView: Get new data from database." );
switch(this.Store)
{
case Store.Road:
this.data = db.GetFramesForRoad( this.Material,
userFit.FrameInseam, this.SortBy, userFit.Weight, userFit.Height );
break;
case Store.Mountain:
this.data = db.GetFramesForMountain( this.RidingStyle.ToString(),
userFit.FrameInseamMin, userFit.FrameInseamMax, userFit.Weight,
this.SortBy );
break;
case Store.Cyclocross:
this.data = db.GetFramesForCyclocross( userFit.FrameInseamMin,
userFit.FrameInseamMax, this.SortBy );
break;
case Store.Manufacturer:
this.data = db.GetFramesForManufacturer( this.Manufacturer,
userFit.FrameInseam, this.SortBy, userFit.Weight, userFit.Height );
break;
}
this.dataView = this.data.DefaultView;
HttpContext.Current.Cache.Insert( "framesData", this.data, null,
DateTime.Now.AddMinutes(1), TimeSpan.Zero );
}
else
{
Page.Trace.Write( "FramesView: Get data from Cache." );
this.data = (DataTable)HttpContext.Current.Cache["framesData"];
this.dataView = this.data.DefaultView;
}
}
private void SortData()
{
switch(this.SortBy)
{
case "PModel":
this.dataView.Sort = "PModel";
break;
case "PGrams":
this.dataView.Sort = "PGrams";
break;
case "PPrice":
this.dataView.Sort = "PPrice";
break;
default:
this.dataView.Sort = "PModel";
break;
}
}
private void ManufacturerChanged(object sender,
FramesViewOptionsEventArgs e)
{
Page.Trace.Write( "FramesView: ManufacturerChanged." );
this.Manufacturer = e.Manufacturer;
this.SortBy = e.SortBy;
this.SetDataSource( true );
this.BuildControlHierarchy();
}
private void MaterialChanged(object sender, FramesViewOptionsEventArgs
e)
{
Page.Trace.Write( "FramesView: MaterialChanged." );
this.Material = e.Material;
this.SortBy = e.SortBy;
this.SetDataSource( true );
this.BuildControlHierarchy();
}
private void RearTravelChanged(object sender,
FramesViewOptionsEventArgs e)
{
Page.Trace.Write( "FramesView: RearTravelChanged." );
this.RidingStyle = (RidingStyle)Enum.Parse( typeof(RidingStyle),
e.RearTravel );
this.SortBy = e.SortBy;
this.SetDataSource( true );
this.BuildControlHierarchy();
}
private void SizeChanged(object sender, FramesViewOptionsEventArgs e)
{
Page.Trace.Write( "FramesView: SizeChanged." );
this.Size = e.Size;
this.SortBy = e.SortBy;
fitCalculator = new FitCalculator( true, this.Size, ref userFit );
this.SetDataSource( true );
this.BuildControlHierarchy();
}
private void SortByChanged(object sender, FramesViewOptionsEventArgs
e)
{
Page.Trace.Write( "FramesView: SortByChanged." );
this.SortBy = e.SortBy;
this.SetDataSource( false );
this.SortData();
this.BuildControlHierarchy();
}
#region Register Client Scripts
public void RegisterScriptForLinkedList(string arrayName, DataTable
data)
{
const int iParentCol = 0;
const int iChildCol = 1;
string parentVal = "";
string prevParentVal = "";
strin nextParentVal = "";
string newLine = TextUtil.CRLF;
char doubleQoute = TextUtil.DoubleQoute;
char comma = TextUtil.Comma;
char space = TextUtil.Space;
string commaVal = "";
string spaceVal = "";
StringBuilder sb = new StringBuilder();
sb.Append( "<script language=" + doubleQoute + "javascript" +
doubleQoute + ">" + newLine );
sb.Append( "var NS4 = (navigator.appName == " + doubleQoute +
"Netscape" + doubleQoute + " && parseInt(navigator.appVersion) < 5);" +
newLine );
sb.Append( "var NSX = (navigator.appName == " + doubleQoute +
"Netscape" + doubleQoute + ");" + newLine );
sb.Append( "var IE4 = (document.all) ? true : false;" + newLine );
sb.Append( newLine );
sb.Append( "var " + arrayName + " = new Array();" + newLine );
//
int rowCount = data.Rows.Count;
for(int iRow = 0; iRow < rowCount; iRow++)
{
DataRow row = data.Rows[iRow];
// get value of first column in row.
parentVal = row[iParentCol].ToString();
// Set previous parent to current row value.
prevParentVal = parentVal;
// Create new array index and values.
sb.Append( arrayName + "[" + iRow + "] = new Array(" );
// Loop through child values and add to this array.
while( parentVal == prevParentVal && iRow <= rowCount)
{
if ( iRow <= rowCount - 1)
nextParentVal = row[iParentCol + 1].ToString();
else
nextParentVal = "";
if ( !((parentVal != prevParentVal) || (parentVal != nextParentVal)
|| (nextParentVal == string.Empty)) )
{
commaVal = comma.ToString();
spaceVal = space.ToString();
}
//
string childVal = row[iChildCol].ToString().Replace( "'", "+" );
sb.Append( doubleQoute + childVal + doubleQoute + commaVal +
spaceVal );
// If no more child values exist exit loop.
if ( parentVal != nextParentVal )
break;
else
iRow += 1;
} // end while
sb.Append( "};" + newLine );
} // end for
//
sb.Append( "</script>" + newLine );
string script = sb.ToString();
Page.RegisterStartupScript( arrayName, script );
}
#endregion
public string Material
{
get { return this.material; }
set { this.material = value; }
}
public string RearTravel
{
get { return this.rearTravel; }
set { this.rearTravel = value; }
}
public decimal Size
{
get { return this.size; }
set { this.size = value; }
}
public string SortBy
{
get { return this.sortBy; }
set { this.sortBy = value; }
}
} // class
} // namespace
// +++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++
// FramesViewOptions class
// +++++++++++++++++++++++++++++++++++++++++++++++++
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using WrenchScience.WSLogic.Data;
using WrenchScience.WSLogic.Utility;
using WrenchScience.WSLogic.WebControls.Events;
using WrenchScience.WSLogic.WebControls.Lists;
namespace WrenchScience.WSLogic.WebControls.PartViews
{
/// <summary>
/// Summary description for FramesNavigator.
/// </summary>
public class FramesViewOptions : Abstract.SkinnedControl,
IFramesViewOptions
{
private PartsDB db = new PartsDB();
private string skinVirtualPath =
"/Skins/Navigation/FramesNavigator.ascx";
private string material;
private string rearTravel;
private decimal size;
private string sortBy;
private Panel materialPanel;
private Panel sizePanel;
private Panel rearTravelPanel;
private Panel manufacturerPanel;
private DropDownList materialList;
private FrameSizeList sizeList;
private DropDownList rearTravelList;
private DropDownList manufacturerList;
private DropDownList sortByList;
public event FramesViewOptionsEventHandler ManufacturerChanged;
public event FramesViewOptionsEventHandler MaterialChanged;
public event FramesViewOptionsEventHandler RearTravelChanged;
public event FramesViewOptionsEventHandler SizeChanged;
public event FramesViewOptionsEventHandler SortByChanged;
protected virtual void
OnManufacturerChanged(FramesViewOptionsEventArgs e)
{
if ( ManufacturerChanged != null )
ManufacturerChanged( this, e );
}
protected virtual void OnMaterialChanged(FramesViewOptionsEventArgs e)
{
if ( MaterialChanged != null )
MaterialChanged( this, e );
}
protected virtual void OnRearTravelChanged(FramesViewOptionsEventArgs
e)
{
if ( RearTravelChanged != null )
RearTravelChanged( this, e );
}
protected virtual void OnSizeChanged(FramesViewOptionsEventArgs e)
{
if ( SizeChanged != null )
SizeChanged( this, e );
}
protected virtual void OnSortByChanged(FramesViewOptionsEventArgs e)
{
if ( SortByChanged != null )
SortByChanged( this, e );
}
public FramesViewOptions()
{
if ( this.SkinVirtualPath == null )
this.SkinVirtualPath = this.skinVirtualPath;
}
protected override void InitializeSkin(Control skin)
{
Page.Trace.Write( "FramesViewOptions: Start InitializeSkin." );
this.manufacturerList =
(DropDownList)skin.FindControl("manufacturerList");
this.manufacturerPanel =
(Panel)skin.FindControl("manufacturerPanel");
this.materialList = (DropDownList)skin.FindControl("materialList");
this.materialPanel = (Panel)skin.FindControl("materialPanel");
this.rearTravelList =
(DropDownList)skin.FindControl("rearTravelList");
this.rearTravelPanel = (Panel)skin.FindControl("rearTravelPanel");
this.sizeList = (FrameSizeList)skin.FindControl("sizeList");
this.sizePanel = (Panel)skin.FindControl("sizePanel");
this.sortByList = (DropDownList)skin.FindControl("sortByList");
if ( this.manufacturerList != null && this.manufacturerPanel != null
)
{
if ( this.Store == Store.Manufacturer )
{
Page.Trace.Write( "FramesViewOptions: Set manufacturerList
properties." );
this.manufacturerList.AutoPostBack = true;
this.manufacturerList.SelectedIndexChanged += new EventHandler(
this.SelectedManufacturerChanged );
if ( !Page.IsPostBack )
this.BuildManufacturerList();
}
else
{
this.manufacturerList.Visible = false;
this.manufacturerPanel.Visible = false;
}
}
if ( this.materialList != null && this.materialPanel != null )
{
if ( this.Store == Store.Road )
{
Page.Trace.Write( "FramesViewOptions: Set materialList properties."
);
this.materialList.AutoPostBack = true;
this.materialList.SelectedIndexChanged += new EventHandler(
this.SelectedMaterialChanged );
if ( !Page.IsPostBack )
this.BuildMaterialList();
}
else
{
this.materialList.Visible = false;
this.materialPanel.Visible = false;
}
}
if ( this.rearTravelList != null && this.rearTravelPanel != null )
{
if ( (this.Store == Store.Mountain) && (this.RidingStyle ==
RidingStyle.XC || this.RidingStyle == RidingStyle.FR || this.RidingStyle
== RidingStyle.FS) )
{
Page.Trace.Write( "FramesViewOptions: Set rearTravelList
properties." );
this.rearTravelList.AutoPostBack = true;
this.rearTravelList.SelectedIndexChanged += new EventHandler(
this.SelectedRearTravelChanged );
if ( !Page.IsPostBack )
this.BuildRearTravelList();
}
else
{
this.rearTravelList.Visible = false;
this.rearTravelPanel.Visible = false;
}
Page.Trace.Write( "FramesViewOptions: End InitializeSkin." );
}
if ( this.sizeList != null && this.sizePanel != null )
{
if ( this.Store == Store.Mountain || this.Store == Store.Road ||
this.Store == Store.Cyclocross )
{
Page.Trace.Write( "FramesViewOptions: Set sizeList properties." );
this.sizeList.AutoPostBack = true;
this.sizeList.SelectedIndexChanged += new EventHandler(
this.SelectedSizeChanged );
if ( !Page.IsPostBack )
{
Page.Trace.Write( "FramesViewOptions: BuildSizeList." );
this.sizeList.Material = this.Material;
this.sizeList.RidingStyle = this.RidingStyle;
this.sizeList.Size = this.Size;
}
}
else
{
this.sizeList.Visible = false;
this.sizePanel.Visible = false;
}
}
if ( this.sortByList != null )
{
Page.Trace.Write( "FramesViewOptions: Set sortByList properties." );
this.sortByList.AutoPostBack = true;
this.sortByList.SelectedIndexChanged += new EventHandler(
this.SelectedSortByChanged );
if ( !Page.IsPostBack )
this.BuildSortByList();
}
}
private void BuildManufacturerList()
{
Page.Trace.Write( "FramesViewOptions: BuildManufacturerList." );
DataTable data = db.GetManufacturersForPartType( "Frame", 'A', 'Z' );
this.manufacturerList.DataTextField = "PMManufacturer";
this.manufacturerList.DataValueField = "PMManufacturer";
this.manufacturerList.DataSource = data;
this.manufacturerList.DataBind();
this.SetSelectedItem( this.manufacturerList, this.Manufacturer );
}
private void BuildMaterialList()
{
Page.Trace.Write( "FramesViewOptions: BuildMaterialList." );
DataTable data = db.GetFrameMaterials( -1, -1, -1 );
this.materialList.DataTextField = "PMaterial";
this.materialList.DataValueField = "PMaterial";
this.materialList.DataSource = data;
this.materialList.DataBind();
this.SetSelectedItem( this.materialList, this.Material );
}
private void BuildRearTravelList()
{
Page.Trace.Write( "FramesViewOptions: BuildRearTravelList." );
this.rearTravelList.Items.Add( new ListItem( "X Country 2.25-4.49in",
RidingStyle.XC.ToString() ) );
this.rearTravelList.Items.Add( new ListItem( "Free Ride 4.5-6in",
RidingStyle.FR.ToString() ) );
this.SetSelectedItem( this.rearTravelList,
this.RidingStyle.ToString() );
}
private void BuildSortByList()
{
Page.Trace.Write( "FramesViewOptions: BuildSortByList." );
if ( this.Store == Store.Manufacturer )
this.sortByList.Items.Add( new ListItem( "model", "PModel" ) );
else
this.sortByList.Items.Add( new ListItem( "manufacturer",
"PManufacturer" ) );
this.sortByList.Items.Add( new ListItem( "grams", "PGrams" ) );
this.sortByList.Items.Add( new ListItem( "price", "PPrice" ) );
this.SetSelectedItem( this.sortByList, this.SortBy );
}
private void SetSelectedItem(ListControl list, string textValue)
{
list.ClearSelection();
ListItem item = list.Items.FindByValue( textValue );
if ( item != null )
item.Selected = true;
}
private void SelectedManufacturerChanged(object sender, EventArgs e)
{
Page.Trace.Write( "FramesViewOptions: SelectedManufacturerChanged
Event Fired." );
string selectedManufacturer = string.Empty;
string selectedSortBy = string.Empty;
selectedManufacturer = this.manufacturerList.SelectedValue;
selectedSortBy = this.sortByList.SelectedValue;
OnManufacturerChanged( new FramesViewOptionsEventArgs(
selectedManufacturer, "", "", 0, selectedSortBy ) );
}
private void SelectedMaterialChanged(object sender, EventArgs e)
{
Page.Trace.Write( "FramesViewOptions: SelectedMaterialChanged Event
Fired." );
string selectedMaterial = string.Empty;
string selectedSortBy = string.Empty;
selectedMaterial = this.materialList.SelectedValue;
selectedSortBy = this.sortByList.SelectedValue;
OnMaterialChanged( new FramesViewOptionsEventArgs( "",
selectedMaterial, "", 0, selectedSortBy ) );
}
private void SelectedRearTravelChanged(object sender, EventArgs e)
{
Page.Trace.Write( "FramesViewOptions: SelectedRearTravelChanged Event
Fired." );
string selectedRearTravel = string.Empty;
string selectedSortBy = string.Empty;
selectedRearTravel = this.rearTravelList.SelectedValue;
selectedSortBy = this.sortByList.SelectedValue;
OnRearTravelChanged( new FramesViewOptionsEventArgs( "", "",
selectedRearTravel, 0, selectedSortBy ) );
}
private void SelectedSizeChanged(object sender, EventArgs e)
{
Page.Trace.Write( "FramesViewOptions: SelectedSizeChanged Event
Fired." );
string selectedSize = string.Empty;
decimal size;
string selectedSortBy = string.Empty;
selectedSize = this.sizeList.SelectedValue;
size = Convert.ToDecimal(selectedSize);
selectedSortBy = this.sortByList.SelectedValue;
OnSizeChanged( new FramesViewOptionsEventArgs( "", "", "", size,
selectedSortBy ) );
}
private void SelectedSortByChanged(object sender, EventArgs e)
{
Page.Trace.Write( "FramesViewOptions: SelectedSortByChanged Event
Fired." );
string selectedSortBy = string.Empty;
selectedSortBy = this.sortByList.SelectedValue;
OnSortByChanged( new FramesViewOptionsEventArgs( "", "", "", 0,
selectedSortBy ) );
}
public string Material
{
get { return this.material; }
set { this.material = value; }
}
public string RearTravel
{
get { return this.rearTravel; }
set { this.rearTravel = value; }
}
public decimal Size
{
get { return this.size; }
set { this.size = value; }
}
public string SortBy
{
get { return this.sortBy; }
set { this.sortBy = value; }
}
} // class
} // namespace
// +++++++++++++++++++++++++++++++++++++++++++++++++