Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Drop Down List Selected Value Problem

Drop Down List Selected Value Problem

Scheduled Pinned Locked Moved ASP.NET
wpfwcfhelp
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kurian_Kurian
    wrote on last edited by
    #1

    Hi am binding the Data in the dropdownlist(cboYY).But after selecting the value am not getting the selected value always getting selectedIndex=-1 and the selected value is getting Null that code as follows string a =Convert.ToString(cboYY.SelectedIndex); string b = cboYY.SelectedValue; Databinding code as follows private void bindYear() { DataTable YearTable = new DataTable(); DataColumn YearColumn; YearColumn = new DataColumn(); YearColumn.DataType = Type.GetType("System.String"); YearColumn.ColumnName = "dobYear"; YearTable.Columns.Add(YearColumn); YearTable.Rows.Add("YYYY"); for (int i = 1940; i <= DateTime.Now.Year; i++) { YearTable.Rows.Add(i); } if (YearTable.Rows.Count > 0) { cboYY.DataSource = YearTable; cboYY.DataBind(); } YearTable.Dispose(); }

    U N 3 Replies Last reply
    0
    • K Kurian_Kurian

      Hi am binding the Data in the dropdownlist(cboYY).But after selecting the value am not getting the selected value always getting selectedIndex=-1 and the selected value is getting Null that code as follows string a =Convert.ToString(cboYY.SelectedIndex); string b = cboYY.SelectedValue; Databinding code as follows private void bindYear() { DataTable YearTable = new DataTable(); DataColumn YearColumn; YearColumn = new DataColumn(); YearColumn.DataType = Type.GetType("System.String"); YearColumn.ColumnName = "dobYear"; YearTable.Columns.Add(YearColumn); YearTable.Rows.Add("YYYY"); for (int i = 1940; i <= DateTime.Now.Year; i++) { YearTable.Rows.Add(i); } if (YearTable.Rows.Count > 0) { cboYY.DataSource = YearTable; cboYY.DataBind(); } YearTable.Dispose(); }

      U Offline
      U Offline
      Unknown Ajanabi
      wrote on last edited by
      #2

      hi if u use following code in page_load then all code use within if(!Page.IsPostback) { ///statemane of ur programm here }

      no knowledge in .net

      K 1 Reply Last reply
      0
      • U Unknown Ajanabi

        hi if u use following code in page_load then all code use within if(!Page.IsPostback) { ///statemane of ur programm here }

        no knowledge in .net

        K Offline
        K Offline
        Kurian_Kurian
        wrote on last edited by
        #3

        it is Listing all the values in the dropdownlist but when i select any value am not getting that value.getting selected value=null or selectedindex=-1

        N 1 Reply Last reply
        0
        • K Kurian_Kurian

          it is Listing all the values in the dropdownlist but when i select any value am not getting that value.getting selected value=null or selectedindex=-1

          N Offline
          N Offline
          Nitin1981
          wrote on last edited by
          #4

          Just check whether you have viewstate enabled or not for the dropdown list.

          Don't Quit

          1 Reply Last reply
          0
          • K Kurian_Kurian

            Hi am binding the Data in the dropdownlist(cboYY).But after selecting the value am not getting the selected value always getting selectedIndex=-1 and the selected value is getting Null that code as follows string a =Convert.ToString(cboYY.SelectedIndex); string b = cboYY.SelectedValue; Databinding code as follows private void bindYear() { DataTable YearTable = new DataTable(); DataColumn YearColumn; YearColumn = new DataColumn(); YearColumn.DataType = Type.GetType("System.String"); YearColumn.ColumnName = "dobYear"; YearTable.Columns.Add(YearColumn); YearTable.Rows.Add("YYYY"); for (int i = 1940; i <= DateTime.Now.Year; i++) { YearTable.Rows.Add(i); } if (YearTable.Rows.Count > 0) { cboYY.DataSource = YearTable; cboYY.DataBind(); } YearTable.Dispose(); }

            U Offline
            U Offline
            Unknown Ajanabi
            wrote on last edited by
            #5

            u can try this protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { bindYear(); } } private void bindYear() { DataTable YearTable = new DataTable(); DataColumn YearColumn; YearColumn = new DataColumn(); YearColumn.DataType = Type.GetType("System.String"); YearColumn.ColumnName = "dobYear"; YearTable.Columns.Add(YearColumn); YearTable.Rows.Add("YYYY"); for (int i = 1940; i <= DateTime.Now.Year; i++) { YearTable.Rows.Add(i); } if (YearTable.Rows.Count > 0) { cboYY.DataSource = YearTable; cboYY.DataTextField = "dobYear"; cboYY.DataBind(); } YearTable.Dispose(); } protected void btn_Click(object sender, EventArgs e) { string a = Convert.ToString(cboYY.SelectedIndex); string b = cboYY.SelectedValue; msg.Text = a + b; }

            no knowledge in .net

            1 Reply Last reply
            0
            • K Kurian_Kurian

              Hi am binding the Data in the dropdownlist(cboYY).But after selecting the value am not getting the selected value always getting selectedIndex=-1 and the selected value is getting Null that code as follows string a =Convert.ToString(cboYY.SelectedIndex); string b = cboYY.SelectedValue; Databinding code as follows private void bindYear() { DataTable YearTable = new DataTable(); DataColumn YearColumn; YearColumn = new DataColumn(); YearColumn.DataType = Type.GetType("System.String"); YearColumn.ColumnName = "dobYear"; YearTable.Columns.Add(YearColumn); YearTable.Rows.Add("YYYY"); for (int i = 1940; i <= DateTime.Now.Year; i++) { YearTable.Rows.Add(i); } if (YearTable.Rows.Count > 0) { cboYY.DataSource = YearTable; cboYY.DataBind(); } YearTable.Dispose(); }

              N Offline
              N Offline
              N a v a n e e t h
              wrote on last edited by
              #6

              Kurian_Kurian wrote:

              string a =Convert.ToString(cboYY.SelectedIndex); string b = cboYY.SelectedValue;

              I guess this you have written this in class and not in any methods. So this value will be set when the class instantiated. At that time dropdown selectedindex will be -1.

              All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups