Need Urgent Help i cannot access value dynamic dropdownlist


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Need Urgent Help i cannot access value dynamic dropdownlist

  1. #1
    Join Date
    Oct 2011
    Posts
    2

    Angry Need Urgent Help i cannot access value dynamic dropdownlist

    Code:
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Data.SqlClient;
     
    public partial class assigned : System.Web.UI.Page
    {
        DropDownList d;
        DropDownList dr;
        protected void Page_Load(object sender, EventArgs e)
        {
     
        }
        protected void TextBox4_TextChanged(object sender, EventArgs e)
        {
            
     
        }       
        
        protected void Button1_Click(object sender, EventArgs e)
        {
            int a = Convert.ToInt32(TextBox1.Text);
           
            try
            {  
               
                for (int i = 0; i < a; i++)
                {
                    d = new DropDownList();
                    d.ID = "Text" + i;
                    LiteralControl l1 = new LiteralControl("<br></br>");
                  
                    d.Items.Add("Rahul");
                    d.Items.Add("Gautum");
                    d.Items.Add("anant");                
                   
                    Panel3.Controls.Add(d);
                    Panel3.Controls.Add(l1);          
                    
                }
                
            }
            catch (Exception e1)
            {
                Label4.Text = "" + e1.Message.ToString();
            }
        }
      
     
        protected void Button2_Click(object sender, EventArgs e)
        {
     
      
          int a = Convert.ToInt32(TextBox1.Text);
                string value = "";
                for (int i = 0; i < a; i++)
                {
                    string str  ="Text" + i;
                    dr = new DropDownList();
                    dr = (DropDownList)(Panel3.FindControl(str));
                   
                    value = dr.SelectedValue.ToString();
                         SqlConnection con = new SqlConnection("Data Source=ABC-0D78787890A;Initial Catalog=Amit;Integrated Security=True");
                   
                    con.Open();
     
                    SqlCommand cmd1 = new SqlCommand("insert into niitstud values('" + value + "')", con);
                    cmd1.ExecuteNonQuery();
                    con.Close();
                   
                    
                }
                    
                }
     
        }
    }

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    What errors are you getting?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Nov 2011
    Posts
    1

    Fix

    Ok, the reason you are not getting info is that when you post back, the control does not exist. You need to rebuild the control again...

    So, instead of building your control in the button event, try to put in your Page_Load a call to build your drop down list and add the content...

    Then your button_2 will get the info...

    I hope this makes sense....

Similar Threads

  1. VB.Net vs Fox Pro vs Access
    By jcb1269 in forum .NET
    Replies: 2
    Last Post: 04-09-2011, 12:40 AM
  2. Converting from access 2002 to access 97
    By wwwursa in forum Database
    Replies: 1
    Last Post: 03-07-2009, 02:20 PM
  3. Urgent Help!! Upsizing Access to ADP: Error: 7874
    By prince123 in forum Database
    Replies: 0
    Last Post: 09-14-2005, 03:11 PM
  4. Replies: 0
    Last Post: 12-20-2000, 01:22 PM
  5. Replies: 0
    Last Post: 11-20-2000, 06:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center