Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
aspx

XML
<table align="center">
<tr>
<td><asp:Label ID="lblmake" runat="server" Text="MAKE"></asp:Label>
</td>
<td><asp:DropDownList ID="ddlMake" Height="20px" Width="300px"
AutoPostBack="True" onselectedindexchanged="ddlMake_SelectedIndexChanged1" runat="server">

</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblRateKW" runat="server" Text="RATING IN KW"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlkw" runat="server" Width="300px" AutoPostBack="True">

</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblNOP" runat="server" Text="NO OF POLES"></asp:Label>  </td>
<td>
<asp:DropDownList ID="ddlNoOfPoles" runat="server" Width="300px">

</asp:DropDownList>
</td>
</tr>


Codebehind file

C#
public partial class DropDownUpdate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            func1();
            func2();
        }
    }
    protected void ddlMake_SelectedIndexChanged1(object sender, EventArgs e)
    {
        string a = ddlMake.SelectedValue;
        func2();
    }
    private void func1()
    {
        SqlConnection con = new SqlConnection("Data Source=192.168.8.122 ;Initial Catalog=SAPDATA;User ID=sp;Password=sp");
        SqlDataAdapter com = new SqlDataAdapter("DP_spA01_Other", con);
        com.SelectCommand.CommandType = CommandType.StoredProcedure;
        DataSet ds = new DataSet();
        if (com != null)
        { com.Fill(ds); }
        ddlMake.DataSource = ds;
        ddlMake.DataTextField = "sMake";
        ddlMake.DataValueField = "sSql1";
        ddlMake.DataBind();
    }
    private void func2()
    {
        SqlConnection con = new SqlConnection("Data Source=192.168.8.122 ;Initial Catalog=SAPDATA;User ID=sp;Password=sp");
        SqlDataAdapter com1 = new SqlDataAdapter("sKw", con);
        com1.SelectCommand.CommandType = CommandType.StoredProcedure;
        com1.SelectCommand.Parameters.AddWithValue("@sKw", ddlkw.SelectedValue);
        DataSet ds1 = new DataSet();
        if (com1 != null)
        { com1.Fill(ds1); }
        ddlkw.DataSource = ds1;
        ddlkw.DataTextField = "sKw";
        ddlkw.DataValueField = "sSql1";
        ddlkw.DataBind();
    }
}

Stord procedure
SQL
Create PROCEDURE  [dbo].[DP_spA01_Other](
	@sSql1 varchar(20),@sMake varchar(1),@sKw varchar(2) ,
	@sFrame varchar(2),@sPoles varchar(4) ,@sMount varchar(4),
	@sInsu varchar(4),@sEnclose varchar(4),@sVolt varchar(4),
	@sFreq varchar(4),@sMKw varchar(15)) 
AS
	if @sSql1="Make"
		select code,PRODESC from a01_d order by code
	if @sSql1="Kw"
		Select distinct(a.code),a.PRODESC,a.kw from a01_ef a ,DP_a01 b 
		where substring(b.accode,5,2)=a.code and substring(b.accode,4,1) = @sMake  order by a.kw
	if @sSql1="Poles"
		Select distinct(a.code),a.PRODESC from a01_g a ,DP_a01 b 
		where substring(b.accode,7,1)=a.code and substring(b.accode,4,1) = @sMake and substring(b.accode,5,2)=@sKw
	If @sSql1="Mounting"
		Select distinct(a.code),a.PRODESC from a01_h a ,DP_a01 b 
		where substring(b.accode,8,1)=a.code and substring(b.accode,4,1) = @sMake and substring(b.accode,5,2)=@sKw   
		and substring(b.accode,7,1)=@sPoles
Posted
Updated 19-Mar-14 2:57am
v4
Comments
Thomas Nielsen - getCore 19-Mar-14 8:51am    
can You please reprase the problem i do not understand what exactly is the problem

1 solution

Change this:
C#
private void func2()
{
SqlConnection con = new SqlConnection("Data Source=192.168.8.122 ;Initial Catalog=SAPDATA;User ID=sp;Password=sp");
SqlDataAdapter com1 = new SqlDataAdapter("sKw", con);
com1.SelectCommand.CommandType = CommandType.StoredProcedure;
com1.SelectCommand.Parameters.AddWithValue("@sKw", ddlkw.SelectedValue);
DataSet ds1 = new DataSet();
if (com1 != null)
{ com1.Fill(ds1); }
 
ddlkw.DataSource = ds1;
ddlkw.DataTextField = "sKw";
ddlkw.DataValueField = "sSql1";
ddlkw.DataBind();
}
 
}


to this

C#
private void func2()
{
SqlConnection con = new SqlConnection("Data Source=192.168.8.122 ;Initial Catalog=SAPDATA;User ID=sp;Password=sp");
SqlDataAdapter com1 = new SqlDataAdapter("sKw", con);
com1.SelectCommand.CommandType = CommandType.StoredProcedure;
com1.SelectCommand.Parameters.AddWithValue("@sKw", ddlMake.SelectedValue);
DataSet ds1 = new DataSet();
if (com1 != null)
{ com1.Fill(ds1); }
 
ddlkw.DataSource = ds1;
ddlkw.DataTextField = "sKw";
ddlkw.DataValueField = "sSql1";
ddlkw.DataBind();
}
 
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900