Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have drodownlist,checkbox with auto postback in Update panel.
Ex
ASP.NET
<asp:updatePanel id="UPD1" runat="Server" UpdateMode="Conditional">
<asp:checkbox id="chk1" runat="server" autopostback="True" OnCheckedChanged="chkAllView_CheckedChanged" />
<asp:dropdownList id="ddl1" runat="server"/>

C#
Protected void Page_Load()
{
  if(!IsPostBack)
{
   DataSet Objds1 = ;

  ddl1.dataSource =Objds1;
  ddl1.databind();

}

}

Protected void chk1_CheckedCObject o,sender e)
{
 If(Chk1.Checked){
  ddl.Items.Clear();}
}

Dropdownlist items is not clear when I click Checkbox.
Please let me know the for Solutions.
Posted
Updated 10-Nov-14 18:20pm
v2
Comments
DamithSL 11-Nov-14 0:28am    
debug your application and check when you check chk1 whether your application hit on chkAllView_CheckedChanged event or not
24983 11-Nov-14 0:35am    
Event is triggered and but not clear dropdownlist
praveenagarkar 11-Nov-14 0:50am    
have you put your checkbox and dropdownlist inside of content template of update panel??? and also script manager in the page??

This is how i have used, its working for me.....
XML
<div>
       <asp:ScriptManager ID="ScriptManager1" runat="server">
       </asp:ScriptManager>
       <asp:UpdatePanel ID="UpdatePanel1" runat="server">
           <ContentTemplate>
               <asp:CheckBox ID="chk1" runat="server" AutoPostBack="True" OnCheckedChanged="chkAllView_CheckedChanged" />
               <asp:DropDownList ID="ddl1" runat="server" />
           </ContentTemplate>
       </asp:UpdatePanel>
   </div><pre lang="cs">

protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              List<string> lst = new List<string>();
              lst.Add("praveen");
              lst.Add("nanda");
              lst.Add("pradeep");
              ddl1.DataSource = lst;
              ddl1.DataBind();
          }

      }

      protected void chkAllView_CheckedChanged(object sender, EventArgs e)
      {
          if (chk1.Checked)
          {
              ddl1.Items.Clear();
          }
      }</pre>


C#

 
Share this answer
 
v2
XML
<asp:DropDownList ID="DropDownList1"  Width="150"  runat="server"  AutoPostBack="true">
    </asp:DropDownList>
 
Share this answer
 
Comments
24983 11-Nov-14 0:43am    
no it does not change.. both controls in Update Panel
XML
  <form id="form1" runat="server">
    <div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:updatePanel id="UPD1" runat="Server" UpdateMode="Conditional">
        <ContentTemplate>
            <br />
            <asp:CheckBox ID="chk1" runat="server" AutoPostBack="true" OnCheckedChanged="chkAllView_CheckedChanged" />
            <asp:DropDownList ID="ddl1" runat="server">
            </asp:DropDownList>          
        </ContentTemplate>
</asp:updatePanel>
    </div>
    </form>


C#
protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                DataSet ds ; //set dataset values here
                ddl1.DataSource=ds;
                ddl1.DataBind();
            }
        }

        protected void chkAllView_CheckedChanged(object sender, EventArgs e)
        {
            if(chk1.Checked)
                ddl1.Items.Clear();
        }


Modify as above.
 
Share this answer
 
v3

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