Results 1 to 4 of 4

Thread: Postback and DropDownList problem [RESOLVED]

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    The Twilight Zone
    Posts
    295

    Postback and DropDownList problem [RESOLVED]

    Hello,

    I have a Dropdownlist which pulls its items from a Database, when the user selects an item a second Dropdownlist becomes visible with items populated with a database again. This all works fine. The Second Dropdownlist in the Page_Load inside a If (IsPostback) Loop. The problem is when the user presses the submit button on the web form the IsPostBack is called and the value i get is the first value in the DropDownlist.

    Hopefully if you see my code you will understand:

    Code:
    private void Page_Load(object sender, System.EventArgs e)
    		{	
    			if (!IsPostBack) 
    			{
    
    				OleDbConnection WO_Conn = new OleDbConnection(ConfigurationSettings.AppSettings["DSN"]);
    
    				string SQL;
    				SQL = "SELECT * FROM MainMenu ORDER BY MainMenuList DESC";
    
    				OleDbCommand myCmd = new OleDbCommand(SQL, WO_Conn);
    
    				OleDbDataReader myReader;
    			
    				WO_Conn.Open();
    
    				myReader = myCmd.ExecuteReader();
    
    				ddlMainMenu.DataSource = myReader;
    				ddlMainMenu.DataTextField = "MainMenuList";
    				ddlMainMenu.DataValueField = "MainMenuList";
    				ddlMainMenu.DataBind();
    
    				myReader.Close();
    				WO_Conn.Close();
    
    			}
    
    			if (IsPostBack) 
    			{
    
    				OleDbConnection WO_Conn = new OleDbConnection(ConfigurationSettings.AppSettings["DSN"]);
    
    				string SQL;
    				SQL = "SELECT * FROM SubMenu WHERE mainMenu  LIKE '%" + ddlMainMenu.SelectedItem.ToString() + "%'";
    
    				OleDbCommand myCmd = new OleDbCommand(SQL, WO_Conn);
    
    				OleDbDataReader myReader;
    
    				WO_Conn.Open();
    
    				myReader = myCmd.ExecuteReader();
    
    				ddlSubMenu.DataSource = myReader;
    				ddlSubMenu.DataTextField = "subMenuList";
    				ddlSubMenu.DataValueField = "subMenuList";
    				ddlSubMenu.DataBind();
    	
    				myReader.Close();
    				WO_Conn.Close();
    
    				ddlSubMenu.Visible = true;
    			}
    		}
    Now when the user clicks the submit form button the second DropDownlist is re-populated and therefore the selected valur from the user is not received. I have tried using session variable to store the selectedValue but this doesn't work.

    Any help greatly appreciated.
    Last edited by modernthinker; Aug 25th, 2005 at 11:06 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
  •  



Click Here to Expand Forum to Full Width