在为控件

时间:2015-06-25 12:51:07

标签: c# asp.net autopostback

所以想象有3个下拉列表控件.contro1,control2,control3。

这些控件在control1的selecteditem中过滤彼此的items.as确定control2上显示的内容,control2确定control3项目列表中显示的内容。

在我的表格中,我必须通过代码从控件3中选择项目并编辑其内容(想象每个控件3项目是发票)。

因此,我必须适当地设置control1-control2-control3 selectedindexes,以便我可以在我的页面中获得正确的发票。

问题是,在设置了control1-control2-control3的索引(得到正确的Invoice)后,control1的回发事件触发,它改变了control2的索引,这意味着它也搞砸了control3的项目...... 所以我的问题是

TL DR:在control1的回发被解雇后,我可以将我的selectedindex保留在control2上吗?

这是我的代码:

    <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>

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 个答案:

没有答案