ASP selectedindex of dropdownlist changes after the postback Event fired for controls

113 views Asked by At

so imagine there are 3 dropdownlist controls.contro1,control2,control3.

these controls filter each other's items.as in control1's selecteditem Determines what is shown on control2 and control2 determines whats shown on control3 item list.

in my form i have to select the item from control 3 via code and edit its contents(imagine each control 3 item is an invoice).

so for doing that i have to set control1-control2-control3 selectedindexes appropriately,so that i can get the right invoice to edit in my page.

problem is, after setting the indexes of control1-control2-and control3(to get the right Invoice),the postback event of control1 fires,and it changes the index of control2,
which means it also messes up control3's items... so my question is

TL DR: can i keep my selectedindex on control2,after control1's postback has fired?

here is my code :

    <td>number One</td>
 <td>
     <asp:DropDownList runat="server" ID="DropA" AutoPostBack="True" DataSourceID="LinqDataSource3" DataTextField="..." DataValueField="..." />
     <asp:LinqDataSource runat="server" EntityTypeName="" ID="LinqDataSource13" ContextTypeName="..." Select="..." TableName="..."></asp:LinqDataSource>
 </td>

 <td>number Two</td>
 <td>
     <asp:DropDownList AutoPostBack="True" ID="DropB" ClientIDMode="Inherit" runat="server" DataSourceID="LinqDataSource5" DataTextField="..." DataValueField="..."  />
     <asp:LinqDataSource runat="server" EntityTypeName="" ID="LinqDataSource14" ContextTypeName="" Select="..." TableName="..." Where="varible1 == @varible1">
         <WhereParameters>
             <asp:ControlParameter ControlID="DropA" PropertyName="SelectedValue" DefaultValue="0" Name="varible1" Type="Int32"></asp:ControlParameter>
         </WhereParameters>
     </asp:LinqDataSource>
 </td>
<td>number Three</td>
 <td>
     <asp:DropDownList AutoPostBack="True" ID="DropC" ClientIDMode="Inherit" runat="server" DataSourceID="LinqDataSource5" DataTextField="..." DataValueField="..."  />
     <asp:LinqDataSource runat="server" EntityTypeName="" ID="LinqDataSource15" ContextTypeName="..." Select="..." TableName="..." Where="varible2 == @varible2">
         <WhereParameters>
             <asp:ControlParameter ControlID="DropB" PropertyName="SelectedValue" Name="varible2" Type="Int32"></asp:ControlParameter>
         </WhereParameters>
     </asp:LinqDataSource>
 </td>

and

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["id"]))
        {
            int varible = int.Parse(Request.QueryString["id"]);
            Model.ClassVar obj = new ClassVar();
            DropA.SelectedValue = obj.idA;
            DropB.SelectedValue = obj.idB;
            DropC.SelectedValue = obj.idC;
        }
    }
}
0

There are 0 answers