Leo Torres
asked on
Combo box sync
i am using VS2010
I have 2 boxes
The value of the first box will be used as a filter to the list in the second box
SELECT DefectCode.Description FROM DefectCode INNER JOIN CategoryDescription ON DefectCode.CategoryKey = CategoryDescription.Catego ryKey AND CategoryDescription.Catego ry = [Value of ComboBox1]
How can I implement the query above to comboBox2
How would I go about doing this??
I have 2 boxes
The value of the first box will be used as a filter to the list in the second box
SELECT DefectCode.Description FROM DefectCode INNER JOIN CategoryDescription ON DefectCode.CategoryKey = CategoryDescription.Catego
How can I implement the query above to comboBox2
How would I go about doing this??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
If you want to know my cs file looks like this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SQ1Interface3
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void DefectCodeList_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
}
}
}
ASKER
I dont see where the event you want me to change is
ASKER
Here is a pic
EEpic.png
EEpic.png
ASKER
Ok made some progress but still can get it to work
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Text;
namespace SQ1Interface3
{
public partial class Default : System.Web.UI.Page
{
public SqlConnection con;
public SqlCommand cmd;
public SqlDataAdapter da;
public DataSet ds, ds1;
protected void Page_Load(object sender, EventArgs e)
{
con = new SqlConnection("Initial Catalog=Square1QualityControl;Integrated Security=True");
}
private void GetCategory()
{
cmd.CommandText = "SELECT DefectCode.Description FROM DefectCode INNER JOIN CategoryDescription ON DefectCode.CategoryKey = CategoryDescription.CategoryKey AND CategoryDescription.Category = '" + DropDownList1.Text + "'";
cmd.Connection = con;
da.Fill(ds1);
DropDownList2.DataSource = ds1.Tables[0];
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
GetCategory();
}
protected void DefectCodeList_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void SqlDataSource1_Updated(object sender, SqlDataSourceStatusEventArgs e)
{
GetCategory();
}
protected void SqlDataSource1_Updated(object sender, SqlDataSourceCommandEventArgs e)
{
GetCategory();
}
}
}
Hi,
Please check this out,
aspx:
code behind:
Hope this helps!
Thanks!
Please check this out,
aspx:
<div>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="TaxClassID"
DataValueField="TaxClassID" AutoPostBack="true"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:yourConnectionString %>"
SelectCommand="SELECT [TaxClassID], [Name] FROM [TaxClass]">
</asp:SqlDataSource>
<br />
<br />
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="SqlDataSource2" DataTextField="TaxRuleID"
DataValueField="TaxRuleID">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:yourConnectionString %>"
SelectCommand="SELECT [TaxRuleID] FROM [TaxRule] WHERE ([TaxClassID] = @TaxClassID)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" PropertyName="SelectedValue"
Name="TaxClassID" Type="Int32" DefaultValue="1"/>
</SelectParameters>
</asp:SqlDataSource>
</div>
code behind:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList2.DataBind();
}
Hope this helps!
Thanks!
ASKER
Ok Made some progress now
But I dont know where I have defined value twice see error attached
I have also attached CS code and aspx code
Error.txt
aspx-code.txt
CS-code.txt
But I dont know where I have defined value twice see error attached
I have also attached CS code and aspx code
Error.txt
aspx-code.txt
CS-code.txt
ASKER
Right Now I just hard coded a value where it says [Value of ComboBox1]
But I need that to be a parameter and I need it to be what ever value is entered for comboBox1