c# - ASP selectedindex of dropdownlist changes after the postback Event fired for controls -
so imagine there 3 dropdownlist controls.contro1,control2,control3.
these controls filter each other's items.as in control1's selecteditem determines shown on control2 , control2 determines whats shown on control3 item list.
in form have select item control 3 via code , edit contents(imagine each control 3 item invoice).
so doing have set control1-control2-control3 selectedindexes appropriately,so can right invoice edit in page.
problem is, after setting indexes of control1-control2-and control3(to right invoice),the postback event of control1 fires,and changes index of control2,
which means messes control3's items... question
tl dr: can keep selectedindex on control2,after control1's postback has fired?
here 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; } } }
Comments
Post a Comment