ASP.NET - drop down selection is retaining its selected values

Asked By muthuraman alexander on 05-Dec-11 02:17 AM
hi all,

i have a drop down list box inside a update panel
;like this

chennai
delhi
mumbai
bangalore
goa

when in  select the goa or mumbai it automatcally goesto the first option ..it was not maitaining the selection
i had populated the drop down in  ( !
IsPostback ) condition
i kept the viewstate enabled and auto post back as true
 

sample code
---------------


<asp:TextBox ID="Code" runat="server" EnableViewState="false" Width="90px"


onkeyup="javascript:RefAddress();" MaxLength="10" ValidationGroup="OPC"


onchange="markRed(this)" OnTextChanged="Code_textChanged" AutoPostBack="true"></asp:TextBox>


<


asp:UpdatePanel ID="Update1" runat="server">


<ContentTemplate>


<asp:DropDownList ID="drp__New" EnableViewState="true" runat="server" Width="200px" AutoPostBack="true">


</asp:DropDownList>


</ContentTemplate>


<Triggers>


<asp:AsyncPostBackTrigger ControlID="Code" />


</Triggers>


</asp:UpdatePanel>



please advice

thanks in advance
MUTHU


Jitendra Faye replied to muthuraman alexander on 05-Dec-11 02:20 AM
Put your TextBox inside UpdatePanel.
dipa ahuja replied to muthuraman alexander on 05-Dec-11 02:22 AM
Implement the selectionIndexChanged EVent of dropdownlist

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
  string value = DropDownList1.SelectedValue.ToString();
  Response.Redirect("default.aspx?city=" + value);
}

Web Star replied to muthuraman alexander on 05-Dec-11 02:22 AM
if you don't doting anything on selection change event than why using AutoPostBack="true"
actully when you selected any item that will goes on first selection either due to rebind of set default selection on selection change event
Chintan Vaghela replied to muthuraman alexander on 05-Dec-11 02:24 AM
Hello

Try as follws

REmove Enable ViewState and added OnSelectedIndexChange Event

protected void Page_Load(object sender, EventArgs e)

      {

        if (!IsPostBack)

        {

          BindDropDown();

        }

}

 

protected void drp_New_SelectedIndexChanged(object sender, EventArgs e)

      {

       

      }

 

<asp:DropDownList ID="drp__New" OnSelectedIndexChanged=” drp_New_SelectedIndexChanged” runat="server" Width="200px" AutoPostBack="true">

</asp:DropDownList>




 

 

Hope this helpful

muthuraman alexander replied to dipa ahuja on 05-Dec-11 04:34 AM
hi thanks for ur reply

actually the selectedIndexchanged event was not firing ...
i have the autopostback prop as true....


thanks in advance
muthu
muthuraman alexander replied to Chintan Vaghela on 05-Dec-11 04:36 AM
hi thank u for ur reply

actually i tried by having auto post back prop as true..
i already populated the drop down inside the !ispostback
also the selected index changed event was not firing ..

please advice me
thanks in advance
muthu