0

我有两个下拉列表。我想在第一个的选择更改上绑定第二个。

这是我的代码:

<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="upCategory" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:MultiView ID="mvSuggestions" ActiveViewIndex="0" runat="server">
            <asp:View ID="vManageCategory" runat="server">
                <table width="100%">
                    <tr>
                        <td style="text-align:center;"> <span class="BlockHeader"><span>Suggestions</span></span>
                        </td>
                    </tr>
                    <tr>
                        <td> <span class="ButtonInput">
                    <span>             

                    <asp:Button ID="btnCreateNew" runat="server" TabIndex="2" 
            Text="Create New Suggestions" onclick="btnCreateNew_Click"  />


                    </span></span>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:GridView ID="gvSuggestion" runat="server" AllowPaging="true" AutoGenerateColumns="false" DataKeyNames="id" Width="285px">
                                <Columns>
                                    <asp:boundfield datafield="suggestion_area" headertext="Suggestions" />
                                    <asp:boundfield datafield="active_closed" headertext="status" />
                                    <asp:boundfield datafield="date_creation" headertext="created date" />
                                </Columns>
                            </asp:GridView>
                        </td>
                    </tr>
                </table>
            </asp:View>
            <asp:View ID="vCreateSuggestions" runat="server">
                <table width="100%">
                    <tr>
                        <td colspan="2" style="text-align:center;"> <span class="BlockHeader"><span>Suggestions</span></span>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2"> <span class="ButtonInput">
                    <span>                                
                    <asp:Button ID="btnShowCategory" runat="server" TabIndex="2" 
            Text="Show Suggestions" onclick="btnShowCategory_Click"  />          
                    </span></span>
                        </td>
                    </tr>
                    <tr>
                        <td rowspan="2">Suggestion Subject</td>
                        <td rowspan="2">
                            <asp:TextBox ID="txtSuggestionSubject" runat="server" TextMode="MultiLine"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="rfvSuggestionSubject" runat="server" ControlToValidate="txtSuggestionSubject" ValidationGroup="Blank" ErrorMessage="Category can not blank!" Display="None" SetFocusOnError="true"></asp:RequiredFieldValidator>
                            <ajaxToolkit:ValidatorCalloutExtender ID="vceSubCategory" TargetControlID="rfvSuggestionSubject" runat="server" Width="120px"></ajaxToolkit:ValidatorCalloutExtender>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="lblCategory" runat="server" Text="Category"></asp:Label>
                        </td>
                        <td>**
                            <asp:DropDownList ID="ddlCategory" runat="server" Height="16px" ValidationGroup="Blank" OnSelectedIndexChanged="ddlCategory_SelectedIndexChanged" Width="210px" AutoPostBack="true"></asp:DropDownList>**
                            <asp:RequiredFieldValidator ID="rfvCategory" runat="server" ControlToValidate="ddlCategory" ValidationGroup="Blank" ErrorMessage="Please select category!" Display="None" InitialValue="0" SetFocusOnError="true"></asp:RequiredFieldValidator>
                            <ajaxToolkit:ValidatorCalloutExtender ID="cveCategory" TargetControlID="rfvCategory" runat="server" Width="230px"></ajaxToolkit:ValidatorCalloutExtender>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="lblSubCategory" runat="server" Text="Sub Category"></asp:Label>
                        </td>
                        <td>
                            <asp:DropDownList ID="ddlSubCategory" runat="server" Width="203px"></asp:DropDownList>
                            <asp:RequiredFieldValidator ID="rfvSubCategory" runat="server" ControlToValidate="ddlSubCategory" ValidationGroup="Blank" ErrorMessage="Please select sub category!" Display="None" InitialValue="0" SetFocusOnError="true"></asp:RequiredFieldValidator>
                            <ajaxToolkit:ValidatorCalloutExtender ID="cveSubCategory" TargetControlID="rfvSubCategory" runat="server" Width="230px"></ajaxToolkit:ValidatorCalloutExtender>
                        </td>
                    </tr>
                    <tr>
                        <td rowspan="2">Suggestion</td>
                        <td rowspan="2">
                            <asp:TextBox ID="txtSuggestion" runat="server" TextMode="MultiLine" Height="75px"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="rfvSuggestion" runat="server" ControlToValidate="txtSuggestion" ValidationGroup="Blank" ErrorMessage="Suggestion can not blank!" Display="None" SetFocusOnError="true"></asp:RequiredFieldValidator>
                            <ajaxToolkit:ValidatorCalloutExtender ID="vceSuggestion" TargetControlID="rfvSuggestion" runat="server" Width="120px"></ajaxToolkit:ValidatorCalloutExtender>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td align="right" colspan="2" style=" padding-right:150px;"> <span class="ButtonInput"><span>
            <asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click" 
                TabIndex="2" Text="Submit" ValidationGroup="Blank" />
            </span></span>
                        </td>
                    </tr>
                </table>
            </asp:View>
        </asp:MultiView>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnCreateNew" EventName="click" />
        <asp:AsyncPostBackTrigger ControlID="btnShowCategory" EventName="click" />
        <asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="click" />**
        <asp:AsyncPostBackTrigger ControlID="ddlCategory" EventName="SelectedIndexChanged" />**</Triggers>
</asp:UpdatePanel>

当我更改 dropdownlistddlCategory时,下拉列表ddlCategory会丢失其值并显示为空白,并且也不会触发SelectionIndexChanged事件。

4

1 回答 1

0

默认情况下,更新面板内的控件将触发异步调用。你不需要为此做任何事情。并且AsyncPostBackTrigger是用于触发异步回发的控件UpdatePanel,这不是您的情况。所以删除以下行:

<asp:AsyncPostBackTrigger ControlID="btnCreateNew" EventName="click" />
<asp:AsyncPostBackTrigger ControlID="btnShowCategory" EventName="click" />
<asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="click" />
<asp:AsyncPostBackTrigger ControlID="ddlCategory"  EventName="SelectedIndexChanged" />

为了更好地理解,我建议阅读AsyncPostBackTrigger 与 PostBackTrigger以及 AsyncPostBackTrigger 和 PostBackTrigger 之间真的有什么不同?.

于 2013-08-29T21:58:11.407 回答