Click here to Skip to main content
15,902,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a drop downlist and 2 list box . I want that i am not able to select anything from listbox 1 and 2 until i am not selecting the item from dropdownlist but every time i select anything from dropdownlist it postback and its value is not resisting .
ASP.NET
<div>
    <asp:DropDownList ID="ddlAdmin" runat="server" >
    <table width="70%">
    <tr><td colspan="3">
    <asp:ListBox ID="ProductListBox" runat="server" SelectionMode="Multiple" ></td>
    <td><asp:Button ID="BtnMoveLeft" runat="server" Text="Add Permission" OnClick="BtnMoveleft_Click" /></td>
    <td>
    
    <asp:ListBox ID="PermissionListBox" runat="server" SelectionMode="Multiple" ></td>
    </tr>
   </table>
    </div>

C#
protected void Page_Load(object sender, EventArgs e)
    {
        FillProductList();
        FillAdminDropDownList();
    }

    protected void FillAdminDropDownList()
    {
        DataManager myData = new DataManager(DbFunctions.GetConnectionString());
        MySqlConnection myPConn = myData.GetPooledConnection(new MySqlConnection());


        MySqlCommand cmd = new MySqlCommand("SELECT adminuserid,adminusername FROM adminusermast", myPConn);
        DataTable dt = new DataTable();
        myPConn.Open();
        MySqlDataAdapter adptr = new MySqlDataAdapter(cmd);
        adptr.Fill(dt);
        myPConn.Close();
        if (dt.Rows.Count > 0)
        {
            ddlAdmin.Items.Clear();
            ddlAdmin.Items.Add("SELECT");
            foreach (DataRow drow in dt.Rows)
            {
                ListItem lst = new ListItem();
                lst.Value = drow[1].ToString();
                lst.Text = drow[0].ToString();
                ddlAdmin.Items.Add(lst);
            }
        }
    }
    protected void FillProductList()
    {
            DataManager myData = new DataManager(DbFunctions.GetConnectionString());
            MySqlConnection myPConn = myData.GetPooledConnection(new MySqlConnection());
            MySqlCommand com = new MySqlCommand("Select productid,productname from productmast", myPConn);
            MySqlDataReader Reader = null;
            myPConn.Open();
           Reader = com.ExecuteReader();
           while (Reader.Read())
           {

               ListItem newItem = new ListItem();
               newItem.Text = Reader["productname"].ToString();
               newItem.Value = Reader["productid"].ToString();
               ProductListBox.Items.Add(newItem);
           }
           Reader.Close();
       myPConn.Close();
    }

    protected void BtnMoveleft_Click(object sender, EventArgs e)
    {
        for (int i = ProductListBox.Items.Count - 1; i >= 0; i--)
        {
            if (ProductListBox.Items[i].Selected == true)
            {
                PermissionListBox.Items.Add(ProductListBox.Items[i]);
                ListItem li = ProductListBox.Items[i];
                ProductListBox.Items.Remove(li);
            }
        }
    }
Posted
Updated 18-Oct-11 20:32pm
v2

initially set DropDownList.Enabled="false"

in the DropDownList2_SelectedIndexChanged
{
DropDownList1.Enabled="true";
}
 
Share this answer
 
Hi ,
If Possibly Put Your dropdownlist in Update Panel.....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900