2014-02-11 94 views
-1

我是新來的asp.net。我有一個在代碼後面填充的下拉列表。當我從下拉列表中選擇任何項目時,應根據表格中的數據填充兩個文本框和另一個下拉列表。填寫下拉列表中的文本框在asp.net中選擇

<asp:DropDownList runat="server" ID="dropDownExisting"></DropDownList><br /> 
<asp:TextBox ID="txtPromotion" runat="server" Width="77px" ></asp:TextBox><br /> 
<asp:TextBox ID="txtSubject" runat="server" Width="288px"></asp:TextBox><br /> 
<asp:DropDownList ID="dropDownType" runat="server"> 
    <asp:ListItem>Monthly Newsleter</asp:ListItem> 
    <asp:ListItem>Webbinar Newsleter</asp:ListItem> 
    <asp:ListItem>Annoucement</asp:ListItem> 
</asp:DropDownList> 

我希望它在客戶端完成。我必須在哪裏提供數據庫連接?我是否需要使用更新面板等Ajax控件?或JavaScript將工作良好?我希望在客戶端。

回答

1

簡單的,你可以在下拉做到這一點SelectedIndexChanged事件

SelectedIndexChanged

編輯

<asp:UpdatePanel ID="upDdlGoal" runat="server" UpdateMode="always"> 
    <ContentTemplate> 
     <asp:DropDownList ID="drop1" runat="server" AutoPostBack="true" EnableViewState="true" OnSelectedIndexChanged="drop1_SelectedIndexChanged">      
</asp:DropDownList> 
    </ContentTemplate> 
    <Triggers> 
     <asp:AsyncPostbackTrigger ControlID="drop1" EventName="SelectedIndexChanged" /> 
    </Triggers> 
</asp:UpdatePanel> 

代碼背後:

VB:

Protected Sub drop1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlAddDepPlans.SelectedIndexChanged 
    //Connectivity coding 
End Sub 

C#:

protected void drop1_SelectedIndexChanged(object sender, System.EventArgs e) 
{ 
    //Connectivity coding 
} 
+0

我知道selectedindex已更改,但是如何在文本框中顯示來自表的數據以及提供連接的位置? – Ami

+0

在selectedindex更改事件中編寫連接代碼並填充 –

+0

比我認爲它會執行回發。我不想那樣。 – Ami

0

客戶端IDE使用JavaScript

的.aspx編碼

<asp:DropDownList runat="server" ID="dropDownExisting" ></asp:DropDownList><br /> 
    <asp:TextBox ID="txtPromotion" runat="server" Width="77px" ></asp:TextBox><br /> 
    <asp:TextBox ID="txtSubject" runat="server" Width="288px"></asp:TextBox><br /> 
    <asp:DropDownList ID="dropDownType" runat="server"> 
     <asp:ListItem>Monthly Newsleter</asp:ListItem> 
     <asp:ListItem>Webbinar Newsleter</asp:ListItem> 
     <asp:ListItem>Annoucement</asp:ListItem> 
    </asp:DropDownList> 

的.cs

protected void Page_Load(object sender, EventArgs e) 
     { 

      dropDownType.Attributes.Add("onChange", "return OnSelectedIndexChange();"); 
     } 

的JavaScript:

​​
+0

其中,我提供數據庫連接的shell以及shell在哪裏聲明哪個列值將顯示在哪個文本框中?在哪裏編寫cs代碼? – Ami

相關問題