2014-03-19 46 views
0

我有一個名爲「DropDownList1」的下拉列表。從下拉列表中選取的任何值都不能刷新頁面,但只能刷新面板我的代碼如下。只刷新下拉框中的值更新

<asp:DropDownList ID="DropDownList1" runat="server" Width="200px" autopostback="true" OnSelectedIndexChanged="DropDownList1sel"> 
    <asp:ListItem Text="abc" Value="0"></asp:ListItem> 
       <asp:ListItem Text="a" Value="1"></asp:ListItem> 
       <asp:ListItem Text="b" Value="2"></asp:ListItem> 
       <asp:ListItem Text="c" Value="3"></asp:ListItem> 
    </asp:DropDownList> 
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
<ContentTemplate> 

<asp:Label ID="Label1" runat="server" Text=""></asp:Label> 

</ContentTemplate> 
</asp:UpdatePanel> 

當我運行這段代碼,它必須調用在「Label1的」填充了ascx.cs名爲「DropDownList1sel」的功能。現在頁面被刷新並且值被填充。我想要刷新面板而不重新加載頁面。請幫忙。

+0

您嘗試過什麼碼?請用代碼編輯您的原始問題。 – Seany84

+0

向我們展示了ascx.cs代碼的一部分 – Jegadeesh

+0

您是否找到適合您問題的解決方案? – Seany84

回答

0

幾件事情要做

套裝UpdateMode=conditional然後添加觸發器爲DropDownList1

<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="conditional" runat="server"> 
<ContentTemplate> 

<asp:Label ID="Label1" runat="server" Text=""></asp:Label> 

</ContentTemplate> 
<Triggers> 
    <asp:AsyncPostBackTrigger ControlID="DropDownList1" 
     EventName="SelectedIndexChanged" /> 
</Triggers> 
</asp:UpdatePanel> 
0

爲什麼不加你的UpdatePanel內的下拉列表。

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
    <ContentTemplate> 
     <asp:DropDownList ID="DropDownList1" runat="server" Width="200px" 
      AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_OnSelectedIndexChanged"> 
      <asp:ListItem Text="abc" Value="0"></asp:ListItem> 
      <asp:ListItem Text="a" Value="1"></asp:ListItem> 
      <asp:ListItem Text="b" Value="2"></asp:ListItem> 
      <asp:ListItem Text="c" Value="3"></asp:ListItem> 
     </asp:DropDownList> 
     <asp:Label ID="Label1" runat="server" Text=""></asp:Label> 
    </ContentTemplate> 
    <Triggers> 
     <asp:PostBackTrigger ControlID="DropDownList1"/> 
    </Triggers> 
</asp:UpdatePanel> 
0

必須放置該面板的更新面板內..

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
    <ContentTemplate> 
     <panel id="panel1"> 
     </panel> 
    </ContentTemplate> 
    <Triggers> 
    <asp:AsyncPostBackTrigger ControlID="DropDownList1" /> 
    </Triggers> 
</asp:UpdatePanel>