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. General Programming
  3. C#
  4. dynamic control (c# ASP.net)

dynamic control (c# ASP.net)

Scheduled Pinned Locked Moved C#
csharpasp-nethelpquestion
2 Posts 2 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.
  • H Offline
    H Offline
    hhems
    wrote on last edited by
    #1

    hi I have created one method createdropdown()in that i had create one dynamic dropdownlist and in selectindexchange of that dropdownlist i had created another dynamic dropdownlist and again selectedindexchange of the second dropdown . but when i run this code it will call first selectedindexchange when i select the dropdownvalue but it want call second selectedindexchange. i had done autopostBack=true for both the dropdownlist. Please Help It is some urgent Task that i have to complet. in the below ddl_SelectedIndexChanged() is call but ddl2____SelectedIndexChanged is not fired.....? // Add DropDownList Control to Placeholder private void CreateDropDownBoxes() { //int counter= Convert[ViewState ("counter"),Int32]; for (int counter = 0; counter <= NumberOfControls; counter++) { DropDownList ddl = new DropDownList(); ddl.ID = "DropDownList_ID" + (counter + 1).ToString(); ddl.AutoPostBack = true; ddl.AppendDataBoundItems = true; ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged); DataTable dt = new DataTable(); dt = getdata_workspace(); ddl.DataSource = dt; ddl.DataTextField = "displayedname"; ddl.DataValueField = "id"; ddl.DataBind(); phDropDownLists.Controls.Add(ddl); phDropDownLists.Controls.Add(new LiteralControl(" ")); } } public void ddl_SelectedIndexChanged(object sender, EventArgs e) { int n = this.NumberOfControls; for (int i = 0; i < n; i++) { SqlConnection conn = new SqlConnection(connStr); string boxName = "DropDownList_ID" + (i + 1).ToString(); DropDownList ddl2_ = phDropDownLists.FindControl(boxName) as DropDownList; DropDownList ddl2___ = new DropDownList(); ddl2___.ID = "DropDownList__" + (i + 1).ToString(); ddl2___.AutoPostBack = true; ddl2___.AppendDataBoundItems = true; ddl2___.EnableViewState = true; SqlCommand cmd = new SqlCommand("select * from unit where workspaceid='" + ddl2_.SelectedValue + "'", conn); conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { ddl2___.Items.Add(dr.GetString(2)); } // ddl2___.EnableViewState = true; ddl2___.SelectedIndexChanged += new EventHandler(ddl2____SelectedIndexChanged); ddl2___.DataTextField = "displayedname"; ddl2___.DataValueField = "id"; phTextBoxes.Controls.Add(ddl2___); phTextBoxes.Controls.Add(new LiteralControl(" ")); } // throw new Exception("The method or operation is not implemented."); } void ddl2____SelectedIndexChanged(object sender, EventArgs e) { int n = this.NumberOfControls; for (int i = 0; i < n; i++) {

    C 1 Reply Last reply
    0
    • H hhems

      hi I have created one method createdropdown()in that i had create one dynamic dropdownlist and in selectindexchange of that dropdownlist i had created another dynamic dropdownlist and again selectedindexchange of the second dropdown . but when i run this code it will call first selectedindexchange when i select the dropdownvalue but it want call second selectedindexchange. i had done autopostBack=true for both the dropdownlist. Please Help It is some urgent Task that i have to complet. in the below ddl_SelectedIndexChanged() is call but ddl2____SelectedIndexChanged is not fired.....? // Add DropDownList Control to Placeholder private void CreateDropDownBoxes() { //int counter= Convert[ViewState ("counter"),Int32]; for (int counter = 0; counter <= NumberOfControls; counter++) { DropDownList ddl = new DropDownList(); ddl.ID = "DropDownList_ID" + (counter + 1).ToString(); ddl.AutoPostBack = true; ddl.AppendDataBoundItems = true; ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged); DataTable dt = new DataTable(); dt = getdata_workspace(); ddl.DataSource = dt; ddl.DataTextField = "displayedname"; ddl.DataValueField = "id"; ddl.DataBind(); phDropDownLists.Controls.Add(ddl); phDropDownLists.Controls.Add(new LiteralControl(" ")); } } public void ddl_SelectedIndexChanged(object sender, EventArgs e) { int n = this.NumberOfControls; for (int i = 0; i < n; i++) { SqlConnection conn = new SqlConnection(connStr); string boxName = "DropDownList_ID" + (i + 1).ToString(); DropDownList ddl2_ = phDropDownLists.FindControl(boxName) as DropDownList; DropDownList ddl2___ = new DropDownList(); ddl2___.ID = "DropDownList__" + (i + 1).ToString(); ddl2___.AutoPostBack = true; ddl2___.AppendDataBoundItems = true; ddl2___.EnableViewState = true; SqlCommand cmd = new SqlCommand("select * from unit where workspaceid='" + ddl2_.SelectedValue + "'", conn); conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { ddl2___.Items.Add(dr.GetString(2)); } // ddl2___.EnableViewState = true; ddl2___.SelectedIndexChanged += new EventHandler(ddl2____SelectedIndexChanged); ddl2___.DataTextField = "displayedname"; ddl2___.DataValueField = "id"; phTextBoxes.Controls.Add(ddl2___); phTextBoxes.Controls.Add(new LiteralControl(" ")); } // throw new Exception("The method or operation is not implemented."); } void ddl2____SelectedIndexChanged(object sender, EventArgs e) { int n = this.NumberOfControls; for (int i = 0; i < n; i++) {

      C Offline
      C Offline
      Chintan Desai
      wrote on last edited by
      #2

      advice 1:do not post whole project in the forum, its irritating, only post the code which u feel as doubtful. advice 2: ur naming convention according to the above code is very very bad. (such as ddl___SelectIndex...). dude:if u wanna quick result for ur problem, follow the advice.:zzz:

      Regards Chintan www.visharadsoft.com (Nothing is so purify as KNOWLEDGE)

      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