SQLpower 0 Light Poster

Hello,

So I basically created SQL Server Database and I got it working with displaying my images and drop downlist and everything, however, I want to make it to display an image only if a continent is selected. So if I select Europe, I would like to receive a picture and short description. Any ideas how can I add the description as well?

So something like:

if(ddlContinents.SelectedValue = "Europe) display image 1"

  protected void Page_Load(object sender, EventArgs e)
        {


            if (Request.QueryString["ImageID"] != null)
            {
                string strQuery = "select Name, ContentType, Data from tblFiles where id=@id";
                SqlCommand cmd = new SqlCommand(strQuery);
                cmd.Parameters.Add("@id", SqlDbType.Int).Value = Convert.ToInt32(Request.QueryString["ImageID"]);
                DataTable dt = GetData(cmd);
                if (dt != null)
                {

                    Byte[] bytes = (Byte[])dt.Rows[0]["Data"];
                    Response.Buffer = true;
                    Response.Charset = "";
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.ContentType = dt.Rows[0]["ContentType"].ToString();
                    Response.AddHeader("content-disposition", "attachment;filename=" + dt.Rows[0]["Name"].ToString());
                    Response.BinaryWrite(bytes);
                    Response.Flush();
                    Response.End();
                }

              }



            if (!IsPostBack)
            {
                ddlContinents.AppendDataBoundItems = true;
                String strConnString = ConfigurationManager
                    .ConnectionStrings["conString"].ConnectionString;
                String strQuery = "select ID, ContinentName from Continents";
                SqlConnection con = new SqlConnection(strConnString);
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = strQuery;
                cmd.Connection = con;
                try
                {
                    con.Open();
                    ddlContinents.DataSource = cmd.ExecuteReader();
                    ddlContinents.DataTextField = "ContinentName";
                    ddlContinents.DataValueField = "ID";
                    ddlContinents.DataBind();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    con.Close();
                    con.Dispose();
                }
            }




        }

        private DataTable GetData(SqlCommand cmd)
        {
            DataTable dt = new DataTable();
            String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
            SqlConnection con = new SqlConnection(strConnString);
            SqlDataAdapter sda = new SqlDataAdapter();
            cmd.CommandType = CommandType.Text;
            cmd.Connection = con;
            try
            {
                con.Open();
                sda.SelectCommand = cmd;
                sda.Fill(dt);
                return dt;
            }
            catch
            {
                return null;
            }
            finally
            {
                con.Close();
                sda.Dispose();
                con.Dispose();
            }
        }
        public void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
        {
            lblResults.Text = "You Selected " +
                              ddlContinents.SelectedItem.Text + " -----> " +
                              ddlCountry.SelectedItem.Text + " -----> " +
                              ddlCity.SelectedItem.Text;

        }
        public void ddlContinents_SelectedIndexChanged(object sender, EventArgs e)
        {



            var continent = ddlContinents.SelectedValue;
            ddlCountry.Items.Clear();
            ddlCountry.Items.Add(new ListItem("--Select Country--", ""));
            ddlCity.Items.Clear();
            ddlCity.Items.Add(new ListItem("--Select City--", ""));

            ddlCountry.AppendDataBoundItems = true;
            String strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
            String strQuery = "select ID, CountryName from Countries where ContinentID=@ContinentID";
            SqlConnection con = new SqlConnection(strConnString);
            SqlCommand cmd = new SqlCommand();
            cmd.Parameters.AddWithValue("@ContinentID", ddlContinents.SelectedItem.Value);
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = strQuery;
            cmd.Connection = con;
            try
            {
                con.Open();
                ddlCountry.DataSource = cmd.ExecuteReader();
                ddlCountry.DataTextField = "CountryName";
                ddlCountry.DataValueField = "ID";
                ddlCountry.DataBind();
                if (ddlCountry.Items.Count > 1)
                {
                    ddlCountry.Enabled = true;
                }
                else
                {
                    ddlCountry.Enabled = false;
                    ddlCity.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
                con.Dispose();
            }
        }

And here is my ASP thingy:

<table> <tr> <td align = "center"> <<asp:image ToolTip = "ASP Image Control" ID="Image1" runat="server" ImageUrl ="Default.aspx?ImageID=1" Height="156px" Width="174px"></asp:image></td> <td align = "center"><<asp:image ToolTip = "ASP Image Control" ID="Image2" runat="server" ImageUrl ="Default.aspx?ImageID=2" Height="156px" Width="174px"></asp:image></td> <td align = "center"> <<asp:image ToolTip = "ASP Image Control" ID="Image3" runat="server" ImageUrl ="Default.aspx?ImageID=3" Height="156px" Width="174px"></asp:image></td> </tr> </table>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.