2012-05-07 28 views

回答

0

您可以將DropDownList放入UpdatePanel中,然後在將AutoPostBack屬性設置爲true後,訂閱SelectedIndexChanged事件。

下面是一個例子:

<%@ Page Language="C#" %> 
<script type="text/C#" runat="server"> 
    protected void OnChange(object sender, EventArgs e) 
    { 
     label.Text = string.Format("Selected value: {0}", ddl.SelectedValue); 
    } 
</script> 

<!DOCTYPE html> 
<html> 
<head> 
    <title></title> 
</head> 
<body> 
    <form id="Form1" runat="server"> 
     <asp:ScriptManager ID="scm" runat="server" /> 

     <asp:UpdatePanel ID="up" runat="server"> 
      <ContentTemplate> 
       <asp:DropDownList 
        ID="ddl" 
        runat="server" 
        AutoPostBack="true" 
        OnSelectedIndexChanged="OnChange"> 
        <asp:ListItem Value="1" Text="item 1" /> 
        <asp:ListItem Value="2" Text="item 2" /> 
        <asp:ListItem Value="3" Text="item 3" /> 
       </asp:DropDownList> 

       <asp:Label ID="label" runat="server" /> 
      </ContentTemplate> 
      <Triggers> 
       <asp:AsyncPostBackTrigger ControlID="ddl" EventName="SelectedIndexChanged" /> 
      </Triggers> 
     </asp:UpdatePanel> 
    </form> 
</body> 
</html> 

要了解更多有關更新面板和ASP.NET AJAX你可能需要看看following article

+0

我是新來的asp.net。你能否提供一些有用的鏈接,以便更容易實現。 – Abhishek

+0

我已經發布了一個例子。另外這裏有一個鏈接,你可以看看:http://www.asp.net/ajax/documentation/live/overview/UpdatePanelOverview.aspx –