Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8816547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:38:48+00:00 2026-06-14T04:38:48+00:00

my 2nd dropdownlist is select financial year has years associated with it and when

  • 0

my 2nd dropdownlist is select financial year has years associated with it and when i am trying to select and year like 2011-2012 its not showing its value on button click instead its changing my selection to 1st one that is 2010-2011 same is happening if i select any other project code from my 1st dropdown i m able to select the 1st value in 2nd dropdownlist not the 2nd item?…..[whats happening is my 2nd dropdown which is showing values linked to my1st dropdownlist is not letting me select its 2nd value and submit if i m selecting the 2 nd value its automatically changing it to 1st value and displaying the result ?]

  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.Configuration;


    public partial class Default2 : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connstr"].ConnectionString);
        DataSet ds = new DataSet();
        SqlCommand cmd = new SqlCommand();
        DataTable dt = new DataTable();

        protected 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();

        }




        protected 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[1].ToString();

                DropDownList2.DataBind();
                DropDownList2.Items.Insert(0, "--Select--");

                cmd.Dispose();
            }
            catch (Exception)
            {

            }

            con.Close();
        }



        protected void Button2_Click(object sender, EventArgs e)
        {
            try
            {


            SqlDataAdapter da = new SqlDataAdapter("select pcode,fyyear,date,salary,ta,contigency,nrc,institcharges,others from monthly where pcode=('" + DropDownList1.SelectedItem.ToString() + "' ) AND fyyear=('" + DropDownList2.SelectedItem.ToString() + "')",con);
                DataTable dt = new DataTable();
                da.Fill(dt);
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }

            catch (Exception ex)
            {
                ex.Message.ToString();
            }



        }



    }

i am also attaching aspx code:

    <%@ Page Title="" Language="C#" MasterPageFile="~/grid.master" AutoEventWireup="true" CodeFile="yearwiseex.aspx.cs" Inherits="Default2" %>

    <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <asp:Label ID="Label1" runat="server" Text="Select Project Code"></asp:Label>
    &nbsp;
    &nbsp;
    <asp:DropDownList ID="DropDownList1" runat="server"
           Height="20px" Width="130px"
           onselectedindexchanged="DropDownList1_SelectedIndexChanged" 
            AutoPostBack="True"> </asp:DropDownList>

        <asp:Label ID="Label2" runat="server" Text="Select Financial Year"></asp:Label>
        &nbsp;&nbsp;
    &nbsp;&nbsp;
    <asp:DropDownList ID="DropDownList2" runat="server" 
            Height="20px" Width="130px"></asp:DropDownList>


        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
        <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" />
        <br />
        <br />
        <br />
        <br />
        <asp:GridView ID="GridView1" runat="server" style="margin-left: 82px" 
            Width="90%" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" 
            BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical">
            <AlternatingRowStyle BackColor="White" />
            <FooterStyle BackColor="#CCCC99" />
            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
            <RowStyle BackColor="#F7F7DE" />
            <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#FBFBF2" />
            <SortedAscendingHeaderStyle BackColor="#848384" />
            <SortedDescendingCellStyle BackColor="#EAEAD3" />
            <SortedDescendingHeaderStyle BackColor="#575357" />
        </asp:GridView>
        <br />
    &nbsp;<br />
        </asp:Content>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:38:49+00:00Added an answer on June 14, 2026 at 4:38 am

    I think you’re looking for MultiSelect. In that case, use a listbox:

    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listbox.aspx

    …and set the selection mode to “Multiple”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

jsfiddle How to make 2nd div streatch to all its vertical place. It has
When using Hibernate 2nd level cache and query cache and not specifying anything inside
I'm reading The C Programming Language (2nd ed.) and near the beginning, it has
its already past 2nd June ! Btw I just want to know is it
@this.Model.ActiveApplicationId @this.Html.DropDownList(applications, new SelectList(this.Model.AllApplications, ApplicationId, Title, this.Model.ActiveApplicationId)) renders... 17 <select id=applications> <option value=16>app 16</option>
2nd Tab when input new values doesnt refresh. The application has to be restarted
I want to change the 2nd dropdownlist based on the choice of 1st dropdownlist.
I'm a 2nd year ICT student. I never did PHP before this year and
Its mine 2nd day on Titanium SDK. I want to show multiple annotations on
How to Select Value from Particular Index i.e. 0, 1st , 2nd ,3rd or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.