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 9238171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:41:53+00:00 2026-06-18T07:41:53+00:00

i have aspx and aspx.cs files when i try to get the selected item

  • 0

i have aspx and aspx.cs files when i try to get the selected item of the

DropDownList

it always get the item at 0 index

<div style="text-align:center">
             <b>Scegliere il nome del report *  </b>  &nbsp;
             <asp:DropDownList id="dropdownlist1" style="width:250px;" runat="server"></asp:DropDownList>
            <br />
            <br /> 

            <br /> 
            <b>Scegliere la data del report </b>  &nbsp; 
            <asp:TextBox runat="server" ID="txtSchedDate" name="txtSchedDate" type="text" cssclass="datebox" style="height:20px;" ReadOnly="true"/>
            <br />
            <br />
            <br />
            <asp:Button ID="Button1" runat="server" Text="Pubblica" OnClientClick="" OnClick="Button1_Click" />
            <br />
            <br />
            <br />
            <br />
            <asp:Label ID="Label1" Font-Names="Arial" Font-Size="15px" runat="server" ForeColor="Red" Font-Bold="True" Text=""></asp:Label>
            <div id="divUpload" style="display:none">
            <div  style="width:200pt;;text-align:center;">Pubblicando...</div>
            </div>
        </div>

the c# code

  protected double size = 1;
  private string connectionString;
  private OracleConnection connection;
  private OracleCommand processNumQuery;
  private int indexdropitem;

  protected void Page_Load(object sender, EventArgs e)
  {


    if (Request["CONNECTSTRING"] == null && Session["CONNECTSTRING"] == null)
    {
        Response.Redirect("sessionup.asp?type=Pubreport");
    }
    else
    {
        if (Request["CONNECTSTRING"] != null)
        {
            connectionString = Request["CONNECTSTRING"].ToString();
        }
        else
        {
            connectionString = Session["CONNECTSTRING"].ToString();
        }


        if (connectionString.IndexOf("DSN=") >= 0)
        {
            Utility util = new Utility();
            connectionString = util.ConnStr(connectionString);
        }
        Session["CONNECTSTRING"] = connectionString;
        connection = new OracleConnection(connectionString);
        connection.Open();

    }
    if (!IsPostBack)
    {
            processNumQuery = new OracleCommand("select distinct nome_report from rpg_notification",connection);
            OracleDataReader reader = processNumQuery.ExecuteReader();

            while (reader.Read())
            {
                dropdownlist1.Items.Insert(0, new ListItem(reader.GetString(0), ""));
            }
            reader.Close();
    }
    }


     protected void Button1_Click(object sender, EventArgs e)
     {

    Response.Write("try :" + dropdownlist1.SelectedIndex + " - " + txtSchedDate.Text + " - " + dropdownlist1.Items[dropdownlist1.SelectedIndex].Text + " - " + Request["txtSchedDate"] + " - ");
     }

i awalys get the 0 index please what i have to do??

  • 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-18T07:41:54+00:00Added an answer on June 18, 2026 at 7:41 am

    ASP.NET is not “smart” enough to pass the actual selected index of submitted drop down list. Instead, it depends on the browser sending the selected value, then depending on the items having different value.

    If there are items with the same value and one of them is selected, the server side SelectedIndex will return the index of the first item having that value. I have just created a quick test and was proven right. (not familiar with any .NET fiddle, sorry)

    In your specific case, all items had empty value due to that line:

    dropdownlist1.Items.Insert(0, new ListItem(reader.GetString(0), ""));
    

    To “fix” your problem just add a value:

    string myValue = reader.GetString(0);
    dropdownlist1.Items.Insert(0, new ListItem(myValue, myValue));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to web development. I have 2 .aspx files and in default
Let's say I have two files default.aspx and the associated default.aspx.cs . default.aspx.cs: protected
I have inherited a Web Application project (3 files per aspx page), along with
When i try to open my Default.aspx page on remote server i get the
I have a File.aspx form where I display all the files. When I upload
I have an .aspx file that outputs an image using the following methods: Server.MapPath(somefile.png)
I have several textboxes in my aspx file (not nested in any other controls),
I have an updateprogress in my aspx file, which has a label control in
I have a ListView in my aspx file like this: <asp:ListView ID=ListView1 runat=server></asp:ListView> and
I have the following markup / code block in the ASPX file. The binding

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.