asp.net的DropDownList 的问题 小弟有一个关于asp.net的DropDownList的问题。 我的DropDownList绑定好数据库的资料。在前台运行时想选中DropDownList内的任一个值旁边的textbook就显出出被选择的值。 小弟知道用按钮事件是能完成的,但是现在要求不用按钮事件,直接点DropDownList选中其中一个值旁边的textbook就显示出该值。希望各位高手能指点一二 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DropDownList 本身就有个事件,选中时触发 SelectedIndexChanged事件设置AutoPostBack="true" <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" onselectedindexchanged="DropDownList1_SelectedIndexChanged"> <asp:ListItem Value="请选择" Text="请选择"></asp:ListItem> <asp:ListItem Value="A" Text="A"></asp:ListItem> <asp:ListItem Value="B" Text="B"></asp:ListItem> </asp:DropDownList> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { this.TextBox1.Text = this.DropDownList1.SelectedValue; } AutoPostBack此属性变成true;SelectedValue HTML里 AutoPostBack此属性变成true;CS里 设置SelectedIndexChanged事件 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { textbox1 = DropDownList1.SelectedItem.Text; } 如果只是这个功能的话 建议用JS<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GetDDLText.aspx.cs" Inherits="Html_GetDDLText" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title> <script type="text/javascript"> function GetDDLText() { var ddl = document.getElementById('ddlTest'); document.getElementById('txtTest').value = ddl.options[ddl.selectedIndex].text } </script></head><body> <form id="form1" runat="server"> <div> <div><asp:dropdownlist ID="ddlTest" runat="server" onchange="GetDDLText()"> <asp:ListItem>北京</asp:ListItem> <asp:ListItem>上海</asp:ListItem> <asp:ListItem>天津</asp:ListItem> </asp:dropdownlist> <asp:TextBox ID="txtTest" runat="server"></asp:TextBox> </div> </div> </form></body></html> repeater嵌套问题 jquery/JS 能否控制一段时间 按钮自动按下 各位大虾,我的操作系统windows2003的,在iss下存在一个格式为.dat的文件却打不开 checkbox问题 log4net 日志文件日期错误。 向窗口发消息的问题 如何实现:点击按钮,先执行一段程序,再弹出模态窗口(要求页面不是空白)? 刚接触asp.net,大虾们推荐几本书 使用web.config文件记录数据库连接的问题 Asp.net使用Ajax更新服务器控件的值 帮忙改个正则吧 感谢了。提取HTML中的Email 关于图片和根目录的问题, 图片没放在根目录下
SelectedIndexChanged事件
设置AutoPostBack="true"
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="请选择" Text="请选择"></asp:ListItem>
<asp:ListItem Value="A" Text="A"></asp:ListItem>
<asp:ListItem Value="B" Text="B"></asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
this.TextBox1.Text = this.DropDownList1.SelectedValue;
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
textbox1 = DropDownList1.SelectedItem.Text;
}
<head runat="server">
<title></title>
<script type="text/javascript">
function GetDDLText() {
var ddl = document.getElementById('ddlTest');
document.getElementById('txtTest').value = ddl.options[ddl.selectedIndex].text
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div><asp:dropdownlist ID="ddlTest" runat="server" onchange="GetDDLText()">
<asp:ListItem>北京</asp:ListItem>
<asp:ListItem>上海</asp:ListItem>
<asp:ListItem>天津</asp:ListItem>
</asp:dropdownlist>
<asp:TextBox ID="txtTest" runat="server"></asp:TextBox>
</div>
</div>
</form>
</body>
</html>