Click here to Skip to main content
15,894,291 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 drop down after selection of 1 drop down page is flicking but i don't want that how can i do this pls help.
XML
<tr>
   <td valign="top" align="left" style="padding-removed 10px;">
      <table cellpadding="4" cellspacing="0" border="0" width="100%">
         <tr>
            <td align="left" valign="top" width="15%">
               <asp:Label ID="lblSelectCustomer" runat="server" Text="Select Customer :" Font-Bold="true"></asp:Label>
               </td>
            <td align="left" valign="top" width="85%">
               <asp:DropDownList ID="ddlSelectCustomer" runat="server"    
                  OnSelectedIndexChanged="ddlSelectCustomer_SelectedIndexChanged"
                  AutoPostBack="true">
               </asp:DropDownList>
            </td>
         </tr>
         <tr>
            <td align="left" valign="top">
               <asp:Label ID="lblSelectAudit" runat="server" 
                  Text="Select Audit :" Font-Bold="true"></asp:Label>
            </td>
            <td align="left" valign="top">
               <asp:DropDownList ID="ddlSelectAudit" runat="server" 
                  OnSelectedIndexChanged="ddlSelectAudit_SelectedIndexChanged"
                  AutoPostBack="true">
               </asp:DropDownList>
            </td>
         </tr>
      </table>
   </td>
</tr>
Posted
Updated 10-Jan-12 5:16am
v5
Comments
m@dhu 10-Jan-12 7:11am    
Did you use update panel?
Amod Kumar Jaiswal 10-Jan-12 7:14am    
i don't want to use update panel into all page i want only 1st drop down
m@dhu 10-Jan-12 7:16am    
Then place the two dropdownlists in two different update panels. :)
devbtl 10-Jan-12 7:15am    
set autopostback to false
m@dhu 10-Jan-12 7:17am    
He is using SelectedIndexChanged event. If autopostback is set to false the event will not be fired.

Hi I am using mvc with jQuery for Dynamic DropDownList
JavaScript
/******************************** COUNTRY DROPDOWN LIST ***************************************/
@Html.DropDownList("CountryId", ViewBag.CountryId as SelectList,"Please Select", new { onchange = "javascript:OnCountryChange(this.value);" })
@Html.DropDownList("CityId")

/*************************** WHEN COUNTRY CHANGED ********************************************/
function OnCountryChange(value) 
{
   $.ajax(
   {
      type: "POST",
      datatype: "json",
      url: "/Location/GetCityListByCountryId",
      data: "cid=" + value,
      ContentType: "application/Json",
      //async: false,
      success: function (data) 
      {
         //alert('inside the secure place');
         //debugger;
         var ddl = $("#CityId");
         ddl.empty();

         if (data.length > 0) 
         {
            $(ddl).append("<option value=''> Please Select</option>");
            $.each(data, function (index, optionData) 
            {
               $(ddl).append("<option value='" + optionData.CityId + "'>" + optionData.Name + "</option>");
            });
         }
      }
   });
}

/*************************** CITY LIST IN CONTROLLER***************************************************************/
public JsonResult GetCityListByCountryId(string cid)
{
   int cId = Convert.ToInt32(cid);
   JsonResult result = new JsonResult();  //db.Cities.Where(c => c.CountryId == cId).ToList();
   result.Data = (from c in db.Cities
                  where c.CountryId == cId
                  select new { CityId = c.CityId, Name = c.Name, }).ToList();
   result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
   return result;
}
 
Share this answer
 
v2
Comments
fjdiewornncalwe 10-Jan-12 11:21am    
Just fixed your formatting. Please use pre tags for your source code. It makes things much easier to follow.
+5 for the excellent suggestion.
paste that code in update panel.
 
Share this answer
 
Comments
Amod Kumar Jaiswal 10-Jan-12 7:15am    
i don't want to use update panel into all page i want only 1st drop down

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