Click here to Skip to main content
12,999,157 members (44,143 online)
Rate this:
 
Please Sign up or sign in to vote.
dropdowlist1 contains project code
dropdownlist2 contains financial year but it should be according to the project code i have selected in dropdownlist1
Posted 30-Oct-12 5:16am
Comments
Anele Ngqandu 30-Oct-12 14:15pm
   
Please write a sudo code for what you want to do and plan your sql statements am sure ull find a way. If you can load a dropdown then already you geting somewhere.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi, i'm giving u a similar soln., just change this according to ur requirements....

Change connection string, query, DataTextField, DataValueField... that's all...

<div>
       <asp:UpdatePanel ID="UpdatePanel2" runat="server">
       <ContentTemplate>
           <asp:DropDownList ID="DropDownList2" runat="server"
               DataSourceID="SqlDataSource2" DataTextField="make"
               DataValueField="id" AutoPostBack="True">
           </asp:DropDownList>
           <asp:SqlDataSource ID="SqlDataSource2" runat="server"
               ConnectionString="<%$ ConnectionStrings:TestDbConnectionString %>"
               SelectCommand="SELECT * FROM [Manufacturer]"></asp:SqlDataSource>
               <br />
           <asp:DropDownList ID="DropDownList1" runat="server"
               DataSourceID="SqlDataSource1" DataTextField="product_name"
               DataValueField="product_id">
           </asp:DropDownList>
           <asp:SqlDataSource ID="SqlDataSource1" runat="server"
               ConnectionString="<%$ ConnectionStrings:TestDbConnectionString %>"
               SelectCommand="SELECT [product_id], [product_name] FROM [product] WHERE ([mid] = @mid)">
               <SelectParameters>
                   <asp:ControlParameter ControlID="DropDownList2" Name="mid"
                       PropertyName="SelectedValue" Type="Int32" />
               </SelectParameters>
           </asp:SqlDataSource>
               </ContentTemplate>
       </asp:UpdatePanel>
       </div>


If u have any clarifications reply to this,...
Mark it if u find this useful...
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

  public void Page_Load(object sender, EventArgs e)
    {
 

        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }
        if (Page.IsPostBack == false)
        {
            string query = "select * from project";
            SqlCommand cmd = new SqlCommand(query, con);
            cmd.CommandType = CommandType.Text;
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adp.Fill(ds);
            DropDownList1.DataSource = ds;
            DropDownList1.DataValueField = ds.Tables[0].Columns[0].ToString();
            DropDownList1.DataTextField = ds.Tables[0].Columns[1].ToString();
            DropDownList1.DataBind();
            DropDownList1.Items.Insert(0, "--Select--");
            cmd.Dispose();
        }
 
        con.Close();
 
    }
 

 

    public void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }
 
        try
        {
            string query1 = "Select * from yearly where pid =" + DropDownList1.SelectedItem.Value.ToString();
            SqlCommand cmd = new SqlCommand(query1, con);
            DataSet ds = new DataSet();
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            adp.Fill(ds);
            DropDownList2.DataSource = ds;
 
            //DropDownList2.DataValueField = ds.Tables[0].Columns[0].ToString();
            DropDownList2.DataTextField = ds.Tables[0].Columns["fyyear"].ToString();
 
            DropDownList2.DataBind();
            DropDownList2.Items.Insert(0, "--Select--");
 
            cmd.Dispose();
        }
        catch (Exception ex)
        {
            ex.Message.ToString();
        }
 
        con.Close();
    }
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 12 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100