Thanks, I try your suggestion but I don't have resolved my problem.
Code:
using System.Data;
using System.Data.Odbc;
using System.Configuration;
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlContinents.AppendDataBoundItems = true;
OdbcConnection myConnectionString = new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString);
String strQuery = "select ID, nome from tbl_login";
OdbcCommand objCmd = new OdbcCommand(strQuery, myConnectionString);
objCmd.CommandType = CommandType.Text;
objCmd.CommandText = strQuery;
try
{
myConnectionString.Open();
ddlContinents.DataSource = objCmd.ExecuteReader();
ddlContinents.DataTextField = "nome";
ddlContinents.DataValueField = "ID";
ddlContinents.DataBind();
}
catch (Exception ex)
{
throw ex;
}
finally
{
myConnectionString.Close();
myConnectionString.Dispose();
}
}
}
protected void ddlContinents_SelectedIndexChanged(object sender, EventArgs e)
{
ddlCountry.Items.Clear();
ddlCountry.Items.Add(new ListItem("--Select Country--", ""));
ddlCity.Items.Clear();
ddlCity.Items.Add(new ListItem("--Select City--", ""));
ddlCountry.AppendDataBoundItems = true;
OdbcConnection myConnectionString = new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString);
String strQuery = "select email from tbl_login " +
"where ID=?";
OdbcCommand objCmd = new OdbcCommand(strQuery, myConnectionString);
objCmd.Parameters.AddWithValue("ID", ddlContinents.SelectedItem.Value);
objCmd.CommandType = CommandType.Text;
objCmd.CommandText = strQuery;
objCmd.Connection = myConnectionString;
try
{
myConnectionString.Open();
ddlCountry.DataSource = objCmd.ExecuteReader();
ddlCountry.DataTextField = "email";
ddlCountry.DataValueField = "email";
ddlCountry.DataBind();
if (ddlCountry.Items.Count > 1)
{
ddlCountry.Enabled = true;
}
else
{
ddlCountry.Enabled = false;
ddlCity.Enabled = false;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
myConnectionString.Close();
myConnectionString.Dispose();
}
}
protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
ddlCity.Items.Clear();
ddlCity.Items.Add(new ListItem("--Select City--", ""));
ddlCity.AppendDataBoundItems = true;
OdbcConnection myConnectionString = new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString);
String strQuery = "select IP_Address from tbl_login " +
"where email=?";
OdbcCommand objCmd = new OdbcCommand(strQuery, myConnectionString);
objCmd.Parameters.AddWithValue("email", ddlCountry.SelectedItem.Value);
objCmd.CommandType = CommandType.Text;
objCmd.CommandText = strQuery;
objCmd.Connection = myConnectionString;
try
{
myConnectionString.Open();
ddlCity.DataSource = objCmd.ExecuteReader();
ddlCity.DataTextField = "IP_Address";
ddlCity.DataValueField = "IP_Address";
ddlCity.DataBind();
if (ddlCity.Items.Count > 1)
{
ddlCity.Enabled = true;
}
else
{
ddlCity.Enabled = false;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
myConnectionString.Close();
myConnectionString.Dispose();
}
}
protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
{
lblResults.Text = "You Selected " +
ddlContinents.SelectedItem.Text + " -----> " +
ddlCountry.SelectedItem.Text + " -----> " +
ddlCity.SelectedItem.Text;
}
}
The problem it's the 'String strQuery'.... you can not manipulate the variable '?'...
Bookmarks