Click here to Skip to main content
16,016,076 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
good evening to all..............

I have one dropdownlist with 5 or 6 item and one checkboxlist populate on dropdownlist value.


my .aspx page code is given below..

XML
<asp:DropDownList ID="ddlstDesignation" AutoPostBack="true" runat="server" Width="193px"                                           onselectedindexchanged="ddlstDesignation_SelectedIndexChanged" Height="25px"> <asp:ListItem Value="--Select--">--Select--</asp:ListItem>                                   <asp:ListItem Value="1">National Sales Manager</asp:ListItem>                                           <asp:ListItem Value="2">Region Manager</asp:ListItem>                                           <asp:ListItem Value="3">Branch Manager</asp:ListItem>                                           <asp:ListItem Value="4">Area Manager</asp:ListItem>                                         <asp:ListItem Value="5">Supervisor</asp:ListItem>
                                           <asp:ListItem Value="6">Salesman</asp:ListItem>                                           </asp:DropDownList>



XML
<cc1:CheckBoxListExCtrl ID="CheckBoxListExCtrl1" RepeatDirection="Horizontal" RepeatColumns="2" runat="server">         </cc1:CheckBoxListExCtrl>



on selecting of dropdownlist value the checkboxlist is populate its work good....but when i select the dropdownlist value every time its submitt the page ...

i need javascript for this selectedindexchange....


my code behind .aspx.cs file are given below

C++
private void BindCheckboxList(string designation)
   {
       if (designation == "1")
       {
           ConnDeemah.Open();
           SqlDataReader nsmDr;
           Cmd = "SELECT Convert(varchar, NSM.NationalSalesManagerCode)+ ' - ' + NSM.NationalSalesManagerName + ' / ' + C.CountryName As NationalSalesManagerName, NSM.NationalSalesManagerCode FROM NationalSalesManager NSM INNER JOIN Country C ON NSM.NationalSalesManagerCode = C.NationalSalesManagerCode ORDER BY NationalSalesManagerName";
           SqlCommand RCMD = new SqlCommand(Cmd, ConnDeemah);
           nsmDr = RCMD.ExecuteReader(CommandBehavior.CloseConnection);
           CheckBoxListExCtrl1.DataSource = nsmDr;
           CheckBoxListExCtrl1.DataTextField = "NationalSalesManagerName";
           CheckBoxListExCtrl1.DataValueField = "NationalSalesManagerCode";
           CheckBoxListExCtrl1.DataBind();
       }
       else if (designation == "2")
       {
           ConnDeemah.Open();
           SqlDataReader nsmDr;
           Cmd = "SELECT Convert(varchar, RMgr.RegionManagerCode)+ ' - ' + RMgr.RegionManagerName + ' / ' + RMst.RegionMstName As RegionManagerName, RMgr.RegionManagerCode FROM RegionManager RMgr INNER JOIN RegionMaster RMst  ON RMgr.RegionManagerCode = RMst.RegionManagerCode ORDER BY RMgr.RegionManagerCode";
           SqlCommand RCMD = new SqlCommand(Cmd, ConnDeemah);
           nsmDr = RCMD.ExecuteReader(CommandBehavior.CloseConnection);
           CheckBoxListExCtrl1.DataSource = nsmDr;
           CheckBoxListExCtrl1.DataTextField = "RegionManagerName";
           CheckBoxListExCtrl1.DataValueField = "RegionManagerCode";
           CheckBoxListExCtrl1.DataBind();
       }
       else if (designation == "3")
       {
           ConnDeemah.Open();
           SqlDataReader nsmDr;
           Cmd = Cmd = "SELECT Convert(varchar, BMgr.BranchManagerCode)+ ' - ' + BMgr.BranchManagerName + ' / ' + DMst.DepotName  As BranchManagerName, BMgr.BranchManagerCode FROM BranchManager BMgr INNER JOIN DepotMaster DMst ON BMgr.BranchManagerCode = DMst.BranchManagerCode ORDER BY BMgr.BranchManagerCode";
           SqlCommand RCMD = new SqlCommand(Cmd, ConnDeemah);
           nsmDr = RCMD.ExecuteReader(CommandBehavior.CloseConnection);
           CheckBoxListExCtrl1.DataSource = nsmDr;
           CheckBoxListExCtrl1.DataTextField = "BranchManagerName";
           CheckBoxListExCtrl1.DataValueField = "BranchManagerCode";
           CheckBoxListExCtrl1.DataBind();
       }
       else if (designation == "4")
       {
           ConnDeemah.Open();
           SqlDataReader nsmDr;
           Cmd = Cmd = Cmd = "SELECT Convert(varchar, AreaManagerCode)+ ' - ' + AreaManagerName As AreaManagerName, AreaManagerCode FROM AreaManager ORDER BY AreaManagerCode";
           SqlCommand RCMD = new SqlCommand(Cmd, ConnDeemah);
           nsmDr = RCMD.ExecuteReader(CommandBehavior.CloseConnection);
           CheckBoxListExCtrl1.DataSource = nsmDr;
           CheckBoxListExCtrl1.DataTextField = "AreaManagerName";
           CheckBoxListExCtrl1.DataValueField = "AreaManagerCode";
           CheckBoxListExCtrl1.DataBind();
       }
       else if (designation == "5")
       {
           ConnDeemah.Open();
           SqlDataReader nsmDr;
           Cmd = Cmd = Cmd = Cmd = "SELECT Convert(varchar, SupervisorCode)+ ' - ' + SupervisorName As SupervisorName, SupervisorCode FROM Supervisor ORDER BY SupervisorCode";
           SqlCommand RCMD = new SqlCommand(Cmd, ConnDeemah);
           nsmDr = RCMD.ExecuteReader(CommandBehavior.CloseConnection);
           CheckBoxListExCtrl1.DataSource = nsmDr;
           CheckBoxListExCtrl1.DataTextField = "SupervisorName";
           CheckBoxListExCtrl1.DataValueField = "SupervisorCode";
           CheckBoxListExCtrl1.DataBind();
       }
       else if (designation == "6")
       {
           ConnDeemah.Open();
           SqlDataReader nsmDr;
           Cmd = Cmd = Cmd = Cmd = Cmd = "SELECT Convert(varchar, SalesmanCode)+ ' - ' + SalesmanName1 As SalesmanName, SalesmanCode FROM Salesman ORDER BY SalesmanCode";
           SqlCommand RCMD = new SqlCommand(Cmd, ConnDeemah);
           nsmDr = RCMD.ExecuteReader(CommandBehavior.CloseConnection);
           CheckBoxListExCtrl1.DataSource = nsmDr;
           CheckBoxListExCtrl1.DataTextField = "SalesmanName";
           CheckBoxListExCtrl1.DataValueField = "SalesmanCode";
           CheckBoxListExCtrl1.DataBind();
       }
   }




C#
protected void ddlstDesignation_SelectedIndexChanged(object sender, EventArgs e)
   {
       if (ddlstDesignation.SelectedValue == "1")
       {
           CheckBoxListExCtrl1.Visible = true;
           BindCheckboxList(ddlstDesignation.SelectedValue);
       }
       else if (ddlstDesignation.SelectedValue == "2")
       {
           CheckBoxListExCtrl1.Visible = true;
           BindCheckboxList(ddlstDesignation.SelectedValue);
       }
       else if (ddlstDesignation.SelectedValue == "3")
       {
           CheckBoxListExCtrl1.Visible = true;
           BindCheckboxList(ddlstDesignation.SelectedValue);
       }
       else if (ddlstDesignation.SelectedValue == "4")
       {
           CheckBoxListExCtrl1.Visible = true;
           BindCheckboxList(ddlstDesignation.SelectedValue);
       }
       else if (ddlstDesignation.SelectedValue == "5")
       {
           CheckBoxListExCtrl1.Visible = true;
           BindCheckboxList(ddlstDesignation.SelectedValue);
       }
       else if (ddlstDesignation.SelectedValue == "6")
       {
           CheckBoxListExCtrl1.Visible = true;
           BindCheckboxList(ddlstDesignation.SelectedValue);
       }
   }




i need javascript slectedindex change means when i select a dropdownlist value then populate the checkboxlist using javascript

please help me...thanks
Posted

1 solution

I believe you want to interact with the page without postback refreshing hte page correct?
You can accomplish this easly, and without JavaScript, using Update Panel[^]
With JavaScript you will need to use AJAX, http://msdn.microsoft.com/en-us/magazine/cc163363.aspx[^] though I would suggest using Jquery[^]
 
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