I have a DropDownList that is populated from an ObjectDataSource

<asp:DropDownList ID="ddlDepartment" runat="server" AutoPostBack="True" 
            DataSourceID="odsGetDeptByFaculty" DataTextField="Dept" DataValueField="FID" 
            onselectedindexchanged="ddlDepartment_SelectedIndexChanged">
        </asp:DropDownList>
        <asp:ObjectDataSource ID="odsGetDeptByFaculty" runat="server" 
            SelectMethod="usp_GetDeptByFaculty" TypeName="DataLayer.StoredProcs">
            <SelectParameters>
                <asp:ControlParameter ControlID="ddlFaulty" Name="fCode" 
                    PropertyName="SelectedValue" Type="String" />
            </SelectParameters>
        </asp:ObjectDataSource>

My problem is when I run the program and select the option from the dropdownlist when the postback happens it returns to the first value in the list. Please help me nip resolve this issue. Many thanks in advance.

Thats because the dropdownlist is repopulating on postback. What you are going to have to do is populate the dropdownlist from the code behind page within a

if (!IsPostBack)

This way it will not repopulate on postback.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.