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

  • Home
  • SEARCH
  • 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 6694797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:08:37+00:00 2026-05-26T06:08:37+00:00

I am using c# and asp.net in my project.I wanted to get the selectedindex

  • 0

I am using c# and asp.net in my project.I wanted to get the selectedindex of the dropdownlist but I am getting always as 0.Here is my code of binding the dropdown list with data

MySqlDataReader dr = null;
        try
        {
            //////////////Opening the connection///////////////

            mycon.Open();
            string str = "select category from lk_category";
            MySqlCommand command = mycon.CreateCommand();
            command.CommandText = str;
            dr = command.ExecuteReader();
            DropDownList1.DataSource = dr;
            DropDownList1.DataValueField = "category";
            DropDownList1.DataBind();
            dr.Close();
            str = "select technology from lk_technology";
            command.CommandText = str;
            dr = command.ExecuteReader();
            DropDownList2.DataSource = dr;
            DropDownList2.DataValueField = "technology";
            DropDownList2.DataBind();
        }
        catch (Exception ex) { Response.Write("Exception reding data" + ex); }
        finally
        {
            //dr.Close();
            mycon.Close();
        }

And I am trying to get selected index by:

 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        catID = DropDownList1.SelectedIndex+1;
    }
    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {

        techID = DropDownList2.SelectedIndex;
    }

Here is my page_load:

protected void Page_Load(object sender, EventArgs e)
{

if (Session["valid"] == null)
    Response.Redirect("admin.aspx");
panel1();///If session valid then show panel1;

}

Please tell me where I am going wrong.

  • 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-05-26T06:08:38+00:00Added an answer on May 26, 2026 at 6:08 am

    That is because you refill the drop down list in page load without checking that it is not post back.

    Warping your try-catch (drop down fill) code with

    if (!this.IsPostBack)
    {
        ...
    }
    

    should solve the problem.

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

Sidebar

Related Questions

I am currently using ASP.NET MVC1 in my project but now i am planing
I have a project with ASP.NET MVC, using Entity Framework to get data from
I am using a asp.net webrole project with a report viewer in Azure Reporting.
I am using asp.net for my project , and I am using the following
I am using jQuery with ASP.NET in a project. Instead of using ASP.NET Ajax,
I developed a few rdlc files that I am using in my asp.net/vb.net project.
I have an ASP.Net project using AJAX that I am putting on a server
I am using ASP.NET and C# in my project. I have a requirement where
I am using Asp.Net/C# in my project , in one of my pages I
I am using Asp.Net/C# in my project.I am using Forms Authentication .Currently I call

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.