Click here to Skip to main content
15,909,325 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
dropdowlist1 contains project code
dropdownlist2 contains financial year but it should be according to the project code i have selected in dropdownlist1
Posted
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.

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

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

XML
<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...
 
Share this answer
 
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();
  }
 
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