我是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会运行良好吗?我想在客户端。
答案 0 :(得分:1)
只需在DropDown 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
}
答案 1 :(得分:0)
客户端使用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的:强>
<script type="text/javascript">
function OnSelectedIndexChange() {
var sel = document.getElementById("dropDownExisting");
var text = sel.options.value;
var out = document.getElementById("txtPromotion");
out.value += text + "\n";
}
</script>
答案 2 :(得分:0)