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. Accessing the selectedIndex of a dynamically created Dropdownlist...

Accessing the selectedIndex of a dynamically created Dropdownlist...

Scheduled Pinned Locked Moved ASP.NET
databasehelpquestion
3 Posts 3 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.
  • R Offline
    R Offline
    Radiv Jeshya
    wrote on last edited by
    #1

    Hai, I have created a footer template in my gridview, This footer template contain many dynamically created controls where the dropdownlist is one. I have created the dropdown and assigned a function to it as follows: DropDownList selPage = new DropDownList(); selPage.ID = "selPage"; selPage.CssClass = "GVFooterSel"; for (int cnt = 0; cnt < GVDoctor.PageCount; cnt++) { int curr = cnt + 1; ListItem item = new ListItem(curr.ToString()); if (cnt == GVDoctor.PageIndex) { item.Selected = true; } selPage.Items.Add(item); } selPage.AutoPostBack = true; selPage.SelectedIndexChanged += new EventHandler(selPage_SelectedIndexChanged); selPage.Attributes.Add("onchange", "selPage_SelectedIndexChanged(this,event)"); The functions gets fired but i can't able to find the control and access its selected index. can any help me?

    :-) Radiv Jeshya :-)

    S U 2 Replies Last reply
    0
    • R Radiv Jeshya

      Hai, I have created a footer template in my gridview, This footer template contain many dynamically created controls where the dropdownlist is one. I have created the dropdown and assigned a function to it as follows: DropDownList selPage = new DropDownList(); selPage.ID = "selPage"; selPage.CssClass = "GVFooterSel"; for (int cnt = 0; cnt < GVDoctor.PageCount; cnt++) { int curr = cnt + 1; ListItem item = new ListItem(curr.ToString()); if (cnt == GVDoctor.PageIndex) { item.Selected = true; } selPage.Items.Add(item); } selPage.AutoPostBack = true; selPage.SelectedIndexChanged += new EventHandler(selPage_SelectedIndexChanged); selPage.Attributes.Add("onchange", "selPage_SelectedIndexChanged(this,event)"); The functions gets fired but i can't able to find the control and access its selected index. can any help me?

      :-) Radiv Jeshya :-)

      S Offline
      S Offline
      saanj
      wrote on last edited by
      #2

      Hi, In the selPage_SelectedIndexChanged event, you can get the selected index of the control by using the following code: int selectedIndex = ((DropDownList)sender).SelectedIndex; I hope it will solve your problem. :) Regards Saanj

      Either you love IT or leave IT...

      1 Reply Last reply
      0
      • R Radiv Jeshya

        Hai, I have created a footer template in my gridview, This footer template contain many dynamically created controls where the dropdownlist is one. I have created the dropdown and assigned a function to it as follows: DropDownList selPage = new DropDownList(); selPage.ID = "selPage"; selPage.CssClass = "GVFooterSel"; for (int cnt = 0; cnt < GVDoctor.PageCount; cnt++) { int curr = cnt + 1; ListItem item = new ListItem(curr.ToString()); if (cnt == GVDoctor.PageIndex) { item.Selected = true; } selPage.Items.Add(item); } selPage.AutoPostBack = true; selPage.SelectedIndexChanged += new EventHandler(selPage_SelectedIndexChanged); selPage.Attributes.Add("onchange", "selPage_SelectedIndexChanged(this,event)"); The functions gets fired but i can't able to find the control and access its selected index. can any help me?

        :-) Radiv Jeshya :-)

        U Offline
        U Offline
        Uma J
        wrote on last edited by
        #3

        Just add a panel in your .aspx page because u need some controls like panel or table or place holder to display the dynamic controls, Your code here, DropDownList selPage = new DropDownList(); selPage.ID = "selPage"; selPage.CssClass = "GVFooterSel"; for (int cnt = 0; cnt < GVDoctor.PageCount; cnt++) { int curr = cnt + 1; ListItem item = new ListItem(curr.ToString()); if (cnt == GVDoctor.PageIndex) { item.Selected = true; } selPage.Items.Add(item); } // add this line and run. Now u could see your dropdown in the interface. Panel1.Controls.Add(selPage); selPage.AutoPostBack = true; selPage.SelectedIndexChanged += new EventHandler(selPage_SelectedIndexChanged); selPage.Attributes.Add("onchange", "selPage_SelectedIndexChanged(this,event)");

        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