Link to home
Start Free TrialLog in
Avatar of Leo Torres
Leo TorresFlag for United States of America

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.CategoryKey AND CategoryDescription.Category = [Value of ComboBox1]

How can I implement the query above to comboBox2

How would I go about doing this??
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Leo Torres

ASKER

webapp

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
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)
        {

        }
    }
}

Open in new window

I dont see where the event you want me to change is
Here is a pic
EEpic.png
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();
            }

           

        }
    }

Open in new window

Hi,

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>

Open in new window


code behind:

 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList2.DataBind();
    }

Open in new window


Hope this helps!

Thanks!
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