can you post the code where you build your query from the drop downs?
Sure ! Below is the code.
Public partial class SelectDate : System.Web.UI.Page {
public string ddlCustval;
public string ddlCustofCustval;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
using (SqlConnection cn_custdrpdwn = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["OPDv1ConnectionString"].ToString()))
{
//open the connection with database
cn_custdrpdwn.Open();
SqlCommand cmd_custdrpdwn = new SqlCommand();
cmd_custdrpdwn.Connection = cn_custdrpdwn;
string sql_custdrpdwn = "SELECT DISTINCT CustomerNameLong FROM Customers";
cmd_custdrpdwn.CommandText = sql_custdrpdwn;
SqlDataAdapter Adapter_custdrpdwn = new SqlDataAdapter();
Adapter_custdrpdwn.SelectCommand = cmd_custdrpdwn;
DataSet ds_custdrpdwn = new DataSet();
Adapter_custdrpdwn.Fill(ds_custdrpdwn);
ddlCust.DataSource = ds_custdrpdwn;
ddlCust.DataTextField = "CustomerNameLong";
ddlCust.DataValueField = "CustomerID";
ddlCust.DataBind();
mygrid1.DataSource = ds_custdrpdwn;
mygrid1.DataBind();
cn_custdrpdwn.Close();
}
} // end of IsPostBack
using (SqlConnection cn_custofcustdrpdwn = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["OPDv1ConnectionString"].ToString()))
{
//open the connection with database
cn_custofcustdrpdwn.Open();
SqlCommand cmd_custofcustdrpdwn = new SqlCommand();
cmd_custofcustdrpdwn.Connection = cn_custofcustdrpdwn;
// set sql query
string sql_custofcustdrpdwn = "SELECT distinct CustofCust FROM CustomersofCustomer WHERE (cocCustomerID = '" + ddlCust.SelectedItem.Value + "')
cmd_custofcustdrpdwn.CommandText = sql_custofcustdrpdwn;
SqlDataAdapter Adapter_custofcustdrpdwn = new SqlDataAdapter();
Adapter_custofcustdrpdwn.SelectCommand = cmd_custofcustdrpdwn;
DataSet ds_custofcustdrpdwn = new DataSet();
Adapter_custofcustdrpdwn.Fill(ds_custofcustdrpdwn) ;
ddlCustofCust.DataSource = ds_custofcustdrpdwn;
ddlCustofCust.DataTextField = "ccdCustomerName";
ddlCustofCust.DataValueField = "ccdCustomerID";
ddlCustofCust.DataBind();
mygrid1.DataSource = ds_custofcustdrpdwn;
mygrid1.DataBind();
cn_custofcustdrpdwn.Close();
}
} // end of IsPostBack
}// end Page_Load
protected void Button1_Click(object sender, EventArgs e)
{
{
using (SqlConnection cn = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["OPDv1ConnectionString"].ToString()))
{
//open the connection with database
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
string sql = "SELECT DISTINCT CustomerName, CustofCust, LName, FName, Address FROM Details WHERE(ORD_Customer = '" + ddlCust.SelectedItem.Value + "') AND (ORD_CustomerOfCustomer = '" + ddlCustofCust.SelectedItem.Value + "') ";
cmd.CommandText = sql;
SqlDataAdapter Adapter = new SqlDataAdapter();
Adapter.SelectCommand = cmd;
DataSet ds = new DataSet();
Adapter.Fill(ds);
mygrid.DataSource = ds;
mygrid.DataBind();
}
}
}
protected void ddlCustofCust_SelectedIndexChanged(object sender, EventArgs e)
{
ddlCustofCustval = ddlCustofCust.SelectedValue;
Response.Write("value changed..");
Response.Write(ddlCustofCustval);
}