Joe
tried this no success. Although you must be right, you are the expert and I'm new to c#.
Hereby the ascx code and the code behind.Can you s
Can you see what stupid mistake i'm making?
ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GPISearch.ascx.cs" Inherits="GPImmo.UI.GPISearch" %>
<link href="GPI.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.style1
{
width: 309px;
}
</style>
<portal:mojoPanel ID="mp1" runat="server" ArtisteerCssClass="art-Post" RenderArtisteerBlockContentDivs="true">
<mp:CornerRounderTop id="ctop1" runat="server" />
<asp:Panel ID="pnlWrapper" runat="server" cssclass="art-Post-inner panelwrapper GPImmo">
<portal:mojoPanel ID="MojoPanel1" runat="server" ArtisteerCssClass="art-PostContent">
<asp:Panel ID="pnlGPImmo" runat="server" CssClass="modulecontent">
<div class="clear">
<asp:UpdatePanel runat="server" ID="Updatepanel1" UpdateMode="Always">
<ContentTemplate>
<table width="100%">
<tr>
<td valign="top" class="style1">
<asp:ImageMap ID="ImageMap1" runat="server" BorderWidth="0px"
ImageUrl="~/Images/france_map_large.gif" onclick="ImageMap1_Click"
HotSpotMode="PostBack" EnableViewState="False">
<asp:PolygonHotSpot Coordinates="271,75,263,85,259,103,258,119,252,119,247,107,255,80,251,76,259,75,260,72" AlternateText="Alsace" PostBackValue="Alsace" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="112,172,93,190,75,174,64,227,54,240,62,242,61,247,81,258,91,245,86,234,89,223,111,220,127,195,123,188,123,181,118,174" AlternateText="Aquitaine" PostBackValue="Aquitaine" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="166,141,158,142,157,148,149,148,149,151,156,158,155,166,152,169,154,180,143,195,144,204,149,204,155,195,161,201,169,196,181,202,192,191,188,185,181,187,179,183,182,180,176,172,178,157,184,152,177,143,169,145" AlternateText="Auvergne" PostBackValue="Auvergne" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="83,46,72,44,72,51,77,61,75,78,92,83,103,79,106,85,112,83,119,92,123,85,113,69,112,57,104,61,88,56,85,57,81,50" AlternateText="Basse Normandie" PostBackValue="Basse Normandie" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="174,92,184,106,201,104,214,119,215,130,211,136,214,140,213,151,204,148,201,156,184,156,186,152,178,140,173,142,167,139,167,124,165,123,165,110,170,103,168,97,168,92" AlternateText="Bourgogne" PostBackValue="Bourgogne" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="82,82,80,100,59,104,53,109,39,104,21,91,11,87,13,83,14,80,9,74,16,70,34,71,36,68,43,67,50,79,57,76" AlternateText="Bretagne" PostBackValue="Bretagne" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="123,79,136,76,145,93,154,93,156,98,166,98,168,103,163,111,163,124,165,127,166,139,155,141,155,146,126,149,116,129,110,130,104,124,108,113,119,109,124,97,123,91,127,86" AlternateText="Centre" PostBackValue="Centre" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="195,44,203,42,210,52,204,79,219,98,221,110,213,115,201,101,186,103,176,90,179,76" AlternateText="Champagne-Ardenne" PostBackValue="Champagne-Ardenne" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="275,236,272,246,268,246,258,254,264,280,272,284,276,277,275,267,279,263" AlternateText="Corse" PostBackValue="Corse" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="218,115,228,106,240,108,247,113,250,122,223,156,214,154,217,144,216,138,213,135,217,130" AlternateText="Franche-Comté" PostBackValue="Franche-Comté" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="137,39,140,43,139,50,140,62,134,68,135,73,122,76,120,70,116,70,115,53,110,53,116,46,124,44,132,43" AlternateText="Haute-Normandie" PostBackValue="Haute-Normandie" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="139,67,146,66,168,71,174,77,175,84,173,90,166,91,165,96,157,96,155,90,147,90,138,75" AlternateText="Île-de-France" PostBackValue="Île-de-France" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="169,198,162,204,165,219,171,227,160,238,152,239,153,244,134,245,131,250,137,256,135,264,140,266,130,271,136,276,142,273,149,277,160,273,160,254,183,241,188,243,200,228,194,219,183,219,178,203" AlternateText="Languedoc-Roussillon" PostBackValue="Languedoc-Roussillon" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="119,155,126,151,146,150,153,159,153,165,149,169,151,180,140,195,135,195,133,192,129,192,126,185,127,181,120,172,115,172,114,170,119,164" AlternateText="Limousin" PostBackValue="Limousin" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="212,55,235,60,241,70,257,69,258,74,246,73,244,76,252,82,244,108,232,102,223,104,223,95,208,80" AlternateText="Lorraine" PostBackValue="Lorraine" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="130,194,114,221,90,225,88,234,94,245,84,257,90,262,104,263,106,259,131,268,135,266,132,264,134,256,129,251,132,243,151,243,149,237,160,235,168,227,162,219,157,200,150,207,142,207,140,197,134,198" AlternateText="Midi-Pyrénées" PostBackValue="Midi-Pyrénées" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="161,8,144,12,143,28,166,37,191,39,190,32" AlternateText="Nord-Pas de Calais" PostBackValue="Nord-Pas de Calaiss" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="84,84,97,85,103,83,117,95,119,100,114,107,105,110,100,124,89,124,82,127,86,143,85,148,79,145,74,147,64,142,58,130,61,125,51,114,61,107,68,107,81,101" AlternateText="Pays de la Loiree" PostBackValue="Pays de la Loire" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="144,31,139,37,145,46,144,63,172,67,176,75,180,61,187,57,188,51,191,48,191,42,166,40" AlternateText="Picardie" PostBackValue="Picardie" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="90,126,84,129,89,147,86,150,78,148,73,153,73,166,91,186,95,186,117,163,116,153,124,149,114,132,109,132,102,126" AlternateText="Poitou-Charentes" PostBackValue="Poitou-Charentes" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="198,221,203,228,190,244,211,248,223,256,240,253,259,234,262,225,252,226,244,217,248,205,239,195,233,196,235,203,226,203,216,216,221,221,216,226,205,221" AlternateText="Provence-Alpes-Côte d'Azur" PostBackValue="Provence-Alpes-Côte d'Azur" HotSpotMode="PostBack" />
<asp:PolygonHotSpot Coordinates="240,154,229,163,227,155,222,158,206,151,202,160,181,159,180,172,185,179,184,184,190,183,195,191,182,205,186,217,208,219,215,224,218,221,213,217,217,208,227,201,233,200,230,193,248,191,250,185,242,174,247,168" AlternateText="Rhône-Alpes" PostBackValue="Rhône-Alpes" HotSpotMode="PostBack" />
</asp:ImageMap>
</td>
<td valign="top">
<table width="100%" style="width: 100%">
<tr>
<td colspan="2">
<h2>
<asp:Label ID="lblcounter" runat="server"></asp:Label>
</h2>
</td>
</tr> <tr>
<td>
<asp:Label ID="Label12" runat="server" Text="Region:"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddRegion" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Locality:"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddLocality" runat="server">
<asp:ListItem Selected="True" Value="0">Town</asp:ListItem>
<asp:ListItem Value="1">Rural</asp:ListItem>
<asp:ListItem Value="2">Village</asp:ListItem>
<asp:ListItem Value="3">Hamlet</asp:ListItem>
<asp:ListItem Value="4">Coastal</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Property type:"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddPropertyType" runat="server">
<asp:ListItem>house</asp:ListItem>
<asp:ListItem>villa</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="Price range:"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddPriceFrom" runat="server">
<asp:ListItem Value="Up to 100.000">Up to 100.000</asp:ListItem>
<asp:ListItem>100.000 - 150.000</asp:ListItem>
<asp:ListItem>150.000 - 200.000</asp:ListItem>
<asp:ListItem>200.000 - 250.000</asp:ListItem>
<asp:ListItem>250.000 - 300.000</asp:ListItem>
<asp:ListItem>300.000 - 400.000</asp:ListItem>
<asp:ListItem Selected="True">400.000 - 500.000</asp:ListItem>
<asp:ListItem>500.000 - 700.000</asp:ListItem>
<asp:ListItem>700.000 - 1.000.000</asp:ListItem>
<asp:ListItem>Above 1.000.000</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label5" runat="server" Text="Min. bedrooms:"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddMinBed" runat="server">
<asp:ListItem Selected="True">1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
</asp:DropDownList>
</td>
<tr>
<td>
<asp:Label ID="Label7" runat="server" Text="Min. bathrooms:"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddMinBath" runat="server">
<asp:ListItem Selected="True">1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label9" runat="server" Text="Min. livingspace:"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddMinHabitable" runat="server">
<asp:ListItem Selected="True">0</asp:ListItem>
<asp:ListItem>50</asp:ListItem>
<asp:ListItem>100</asp:ListItem>
<asp:ListItem>150</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label11" runat="server" Text="Min. landsize:"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddMinLand" runat="server">
<asp:ListItem Selected="True">0</asp:ListItem>
<asp:ListItem>1000</asp:ListItem>
<asp:ListItem>2000</asp:ListItem>
<asp:ListItem>4000</asp:ListItem>
<asp:ListItem>5000</asp:ListItem>
<asp:ListItem>10000</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" CssClass="buttonlink"
onclick="Button1_Click" Text="Search" />
</td>
<td>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblsql" runat="server" Text=""></asp:Label>
</td>
</tr>
</tr>
</table>
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel runat="server" id="gridpanel" UpdateMode="Conditional">
<ContentTemplate>
<div class="cleared">
Search results:
<br />
<mp:mojoGridView ID="mojoGridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" OnPageIndexChanging="gridView_PageIndexChanging"
onselectedindexchanged="mojoGridView1_SelectedIndexChanged"
Width="100%">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<div class="property">
<div class="img">
<asp:label runat="server" Text='<%# ShowMainPhoto(Convert.ToInt32(Eval("ReferenceNumber"))) %>' ID="Labelmainphoto" />
</div>
<div class="details">
<div class="description">
<asp:Label ID="lbldesc" runat="server" Text='<%# ShowDescription(Convert.ToString(Eval("ShortDescription"))) %>'></asp:Label>
</div>
<div class="title">
<asp:Label ID="lblreference" runat="server" Text='<%# Bind("ReferenceNumber") %>'></asp:Label>
</div>
<br />
<div class="price">
<asp:Label runat="server" ID="lblprice" Text='<%# String.Format("{0:€ #,#}", (DataBinder.Eval(Container.DataItem, "SalesPrice"))) %>'></asp:Label>
</div>
<div class="readmore">
</div>
</div>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerSettings Position="TopAndBottom" />
</mp:mojoGridView>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:Panel>
</portal:mojoPanel>
</asp:Panel>
<mp:CornerRounderBottom id="cbottom1" runat="server" />
</portal:mojoPanel>
and the code behind
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Globalization;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using mojoPortal.Web;
using mojoPortal.Web.Framework;
using mojoPortal.Web.UI;
using log4net;
using GPImmo.Business;
using Resources;
using System.Data.Sql;
using System.Data.SqlClient;
namespace GPImmo.UI
{
public partial class GPISearch : SiteModuleControl
{
#region OnInit
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.Load += new EventHandler(Page_Load);
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
try
{
SiteUtils.SetFormAction(Page, Request.RawUrl);
PopulateControls();
}
catch (MissingMethodException)
{ }
// LoadData();
}
private static string GetConnectionString()
{
return ConfigurationManager.AppSettings["GPImmoConnectionString"];
}
private void PopulateControls()
{
if (this.ModuleConfiguration != null)
{
this.Title = this.ModuleConfiguration.ModuleTitle;
this.Description = this.ModuleConfiguration.FeatureName;
}
SqlConnection conn = new SqlConnection(GetConnectionString());
conn.Open();
SqlCommand sqlcommand = new SqlCommand("select Name from propertytype");
sqlcommand.Connection = conn;
SqlDataReader dr = sqlcommand.ExecuteReader();
//SqlDataAdapter sqldataadapter = new SqlDataAdapter(sqlcommand);
ddPropertyType.Items.Clear();
ListItem li = new ListItem();
li.Text = "Any";
li.Value = "Any";
ddPropertyType.Items.Add(li);
while (dr.Read())
{
ListItem listitem = new ListItem();
listitem.Text = (string) dr["Name"];
listitem.Value = (string)dr["Name"];
ddPropertyType.Items.Add(listitem);
}
dr.Close();
//'ddRegion
sqlcommand.CommandText = "Select Name From Region";
SqlDataReader drregion = sqlcommand.ExecuteReader();
ddRegion.Items.Clear();
ListItem li2 = new ListItem();
li2.Text = "Any";
li2.Value = "Any";
ddRegion.Items.Add(li2);
while (drregion.Read())
{ ListItem listitem = new ListItem();
listitem.Text = (string)drregion["Name"];
listitem.Value = (string)drregion["Name"];
ddRegion.Items.Add(listitem);
}
drregion.Close();
sqlcommand.CommandText = "Select count(*) from propertyobject where publishonwebsite = 1 ";
Int32 counter = (Int32)sqlcommand.ExecuteScalar();
lblcounter.Text = "Properties online : " + counter.ToString();
//lblcounter
conn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
LoadData();
}
protected void ImageMap1_Click(object sender, ImageMapEventArgs e)
{
ddRegion.SelectedValue = e.PostBackValue.ToString();
LoadData();
}
private void LoadData()
{
SqlConnection conn = new SqlConnection(GetConnectionString());
conn.Open();
String szSQL = String.Empty ;
// first filter is property type
szSQL = "Select * from vwproperties Where ";
switch (ddPriceFrom.SelectedItem.ToString())
{
case "Up to 100.000": szSQL += " SalesPrice < 100000 "; break;
case "100.000 - 150.000": szSQL += " SalesPrice Between 100000 and 150000 "; break;
case "150.000 - 200.000": szSQL += " SalesPrice Between 150000 and 200000 "; break;
case "200.000 - 250.000": szSQL += " SalesPrice Between 200000 and 250000 "; break;
case "250.000 - 300.000": szSQL += " SalesPrice Between 250000 and 300000 "; break;
case "300.000 - 400.000": szSQL += " SalesPrice Between 300000 and 400000 "; break;
case "400.000 - 500.000": szSQL += " SalesPrice Between 400000 and 500000 "; break;
case "500.000 - 700.000": szSQL += " SalesPrice Between 500000 and 700000 "; break;
case "700.000 - 1.000.000": szSQL += " SalesPrice Between 700000 and 100000 "; break;
case "Above 1.000.000": szSQL += " SalesPrice > 1000000 "; break;
default: break;
}
string region = Convert.ToString(ddRegion.SelectedValue);
int nminbed = Convert.ToInt32(ddMinBed.SelectedValue);
int nminbath = Convert.ToInt32(ddMinBath.SelectedValue);
int nminliving = Convert.ToInt32(ddMinHabitable.SelectedValue);
int nminland = Convert.ToInt32(ddMinLand.SelectedValue);
int nloc = Convert.ToInt32(ddLocality.SelectedValue);
szSQL += " AND NumberOfBedRooms > " + nminbed + " ";
szSQL += " AND NumberOfBathRooms > " + nminbath + " ";
szSQL += " AND HabitableSurface > " + nminliving + " ";
szSQL += " AND TotaleSurface > " + nminland + " ";
// to avoid any
if (nloc>-1)
szSQL += " AND Locality = " + nloc;
if (region.Contains("'"))
region = region.Replace("'", "%");
if (region != "Any")
szSQL+= " AND Region like '" + region + "' " ;
string proptype = Convert.ToString(ddPropertyType.SelectedValue);
if (proptype != "Any")
szSQL += " AND PropertyType = '" + proptype + "'";
SqlCommand sqlcommand = new SqlCommand(szSQL );
sqlcommand.Connection = conn;
SqlDataAdapter sqldataadapter = new SqlDataAdapter(sqlcommand);
DataSet ds = new DataSet();
sqldataadapter.Fill(ds);
mojoGridView1.DataSource = ds.Tables[0];
lblsql.Text = "Found: " + ds.Tables[0].Rows.Count.ToString() + "properties";
mojoGridView1.DataBind();
conn.Close();
gridpanel.Update();
}
protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
mojoGridView1.PageIndex = e.NewPageIndex;
LoadData();
}
protected void mojoGridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
#region gridfunctions
protected string ShowDescription(string desc)
{
string ret = String.Empty;
if (desc.Length > 50)
ret = desc.Substring(0, 50);
else
ret = desc;
return ret;
}
protected string ShowMainPhoto(Int32 refnr)
{
SqlConnection conn = new SqlConnection(GetConnectionString());
conn.Open();
SqlCommand sqlcommand = new SqlCommand("select * from VWMAINIMAGE Where ReferenceNumber = " + refnr );
sqlcommand.Connection = conn;
string szFileLink = "";
SqlDataReader dr = sqlcommand.ExecuteReader();
if (dr.HasRows == true)
while (dr.Read())
{
szFileLink = "http://backoffice.gp-immo.com//ObjectImages//";
DateTime created = (DateTime)dr["CreationDate"];
string filename = (string)dr["ImageName"];
DateTime dt = new DateTime(2008,9,16);
if ((DateTime)dr["CreationDate"]> new System.DateTime(2008, 9, 16))
{
szFileLink += refnr.ToString() + "//";
}
szFileLink += filename;
}
dr.Close();
conn.Close();
// string szurl = "this is the result of the function";
string szurl = "<a class=\"foto\" target=\"_self\" href=\"propertyDetail.aspx?property=" + refnr + "\"> <img src=\"" + szFileLink + "\" width=\"180px\"></a>";
return szurl;
}
#endregion
}
}