// auxiliary code for multipage nav demo
void Page_Load ( Object source, EventArgs e ) {
if ( ! IsPostBack ) {
gvCities.SelectedIndex = 0;
gvCities.DataBind ( );
getSelected ( null, null );
}
}
void getSelected ( Object src, EventArgs e ) {
DataKey keys = gvCities.SelectedDataKey;
string country = keys [ 0 ].ToString ( );
string state = keys [ 1 ].ToString ( );
string city = keys [ 2 ].ToString ( );
ViewState [ "destination" ] = city + ", " + getCountry ( country );
// bind destination images
string query = "SELECT Top 18 Caption, ThumbnailUrl, Url FROM DestImages WHERE Country = '" + country +
( state != "" ? "' and StateProvince = '" + state : "" ) +
"' and City = '" + city + "' ORDER BY Caption";
lstImages.DataSource = fetchReader ( query );
lstImages.DataBind ( );
mvImages.ActiveViewIndex = 0;
}
void resetSelected ( Object src, EventArgs e ) {
gvCities.SelectedIndex = 0;
gvCities.DataBind ( );
getSelected ( null, null );
}
void showViewThumbs ( object src, EventArgs e ) {
mvImages.SetActiveView ( viewThumbs );
}
void showViewZoom ( object src, DataListCommandEventArgs e ) {
string query = "SELECT Caption, ShortDesc, Url, Width, Credit, CreditLink, Supplier FROM DestImages WHERE Url = '" + e.CommandArgument + "'";
fvZoom.DataSource = fetchReader ( query );
fvZoom.DataBind ( );
mvImages.SetActiveView ( viewZoom );
}
void setImages ( object src, DataListItemEventArgs e ) {
// handles the onItemDataBound event of the destImages datalist
if ( e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem ) {
// set reference to current data record
IDataRecord dataRow = ( IDataRecord ) e.Item.DataItem;
ImageButton imgThumb = ( ImageButton ) e.Item.FindControl ( "imgThumb" );
imgThumb.ImageUrl = dataRow [ "ThumbnailUrl" ].ToString ( ).StartsWith ( "http" ) ?
dataRow [ "ThumbnailUrl" ].ToString ( ) :
string.Format ( "http://images.travelnow.com/{0}", dataRow [ "ThumbnailUrl" ] );
imgThumb.CommandArgument = dataRow [ "Url" ].ToString ( ).StartsWith ( "http" ) ?
dataRow [ "Url" ].ToString ( ) :
string.Format ( "http://images.travelnow.com/{0}", dataRow [ "Url" ] );
string caption = dataRow [ "Caption" ].ToString ( );
imgThumb.ToolTip = caption;
imgThumb.AlternateText = caption;
imgThumb.Attributes [ "onMouseOver" ] = "status='" +
ViewState [ "destination" ].ToString ( ).Replace ( "'", "\\'" ) +
" " + caption.Replace ( "'", "\\'" ) + "';return true";
}
}
void getZoom ( Object src, EventArgs e ) {
FormView fvZoom = ( FormView ) src;
if ( fvZoom.DataItemCount > 0 ) {
// set reference to current data record
IDataRecord dataRow = ( IDataRecord ) fvZoom.DataItem;
string imgUrl = "", imgCaption = "", imgCredit = "", imgCreditLink = "", imgSupplier = "";
int w = 0;
imgUrl = dataRow [ "Url" ].ToString ( );
imgUrl = imgUrl.StartsWith ( "http" ) ? imgUrl :
string.Format ( "http://images.travelnow.com/{0}", imgUrl );
w = Convert.ToInt32 ( dataRow [ "Width" ] );
imgCaption = dataRow [ "shortdesc" ].ToString ( );
imgCredit = dataRow [ "credit" ].ToString ( );
imgCreditLink = dataRow [ "creditlink" ].ToString ( );
imgSupplier = dataRow [ "supplier" ].ToString ( );
Label lblCaption = ( Label ) fvZoom.FindControl ( "lblCaption" );
lblCaption.Text = imgCaption;
ImageButton imgZoom = ( ImageButton ) fvZoom.FindControl ( "imgZoom" );
imgZoom.ImageUrl = imgUrl.Contains ( "wiki" ) && w > 800 ?
imgUrl.Replace ( "/commons/", "/commons/thumb/" ).Replace ( "/en/", "/en/thumb/" ) +
"/800px-" + imgUrl.Substring ( imgUrl.LastIndexOf ( "/" ) + 1 ) : imgUrl;
if ( ! ( imgUrl.Contains ( "wiki" ) && w > 800 ) ) imgZoom.Width = 800;
imgZoom.ToolTip = dataRow [ "Caption" ].ToString ( );
imgZoom.AlternateText = dataRow [ "Caption" ].ToString ( );
Panel imgCredits = ( Panel ) fvZoom.FindControl ( "imgCredits" );
if ( imgCredit != "" ) {
Label lblPrefix = new Label ( );
lblPrefix.Text = "Photography: ";
imgCredits.Controls.Add ( lblPrefix );
if ( imgCreditLink != "" ) {
HyperLink lnkCredits = new HyperLink ( );
lnkCredits.Text = imgCredit;
lnkCredits.NavigateUrl = imgCreditLink;
lnkCredits.Target = "credits";
imgCredits.Controls.Add ( lnkCredits );
}
else {
Label lblCredits = new Label ( );
lblCredits.Text = imgCredit;
imgCredits.Controls.Add ( lblCredits );
}
Label lblSuffix = new Label ( );
lblSuffix.Text = " ";
imgCredits.Controls.Add ( lblSuffix );
}
else {
Label lblPad = new Label ( );
lblPad.Text = " ";
imgCredits.Controls.Add ( lblPad );
}
Label lblSource = new Label ( );
lblSource.Text = "Source: " + imgSupplier;
imgCredits.Controls.Add ( lblSource );
}
}
string getCountry ( string countryCode ) {
return Convert.ToString ( fetchScalar ( "SELECT CountryName FROM Countries WHERE CountryCode = '" +
countryCode + "'" ) );
}