关于 DropDownList 控件的问题

cqnetboy 2003-08-22 08:22:18
请问当 DropDownList 选择过后触发的事件是什么?怎么用啊?
就是选择下拉菜单里某一项后触发的事件?

急,盼高手指点!!
...全文
28 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
caoit 2003-08-22
  • 打赏
  • 举报
回复
<asp:DropDownList
autopostback="true"
OnSelectedIndexChanged="..."
</asp:DropDownList>
caoit 2003-08-22
  • 打赏
  • 举报
回复
加上这个属性
AutoPostBack="True"

记得给分啊
wacle 2003-08-22
  • 打赏
  • 举报
回复
你需要把dropdownlist的autopostback属性设置为true,才可以触发事件
酋长 2003-08-22
  • 打赏
  • 举报
回复
我不是已经告诉你方法和步骤了,照着做就可以了呀!!!!!!!!!!
cqnetboy 2003-08-22
  • 打赏
  • 举报
回复
高手们,回答一下啊,急!!!!!
cqnetboy 2003-08-22
  • 打赏
  • 举报
回复
是这样的啊,双击也能进入那个事件,但是就是点击过后没反应....
给个示例看看啊,谢谢!!
酋长 2003-08-22
  • 打赏
  • 举报
回复
双击dropdownlist进入dropdownlist1_selectedindexchanged事件
去掉事件前面的 private,然后到html文档中,在dropdownlist中加入onclick="drop...changed"事件,ok!!!!!!!!!1
cqnetboy 2003-08-22
  • 打赏
  • 举报
回复
倒,不是RadioButtonList,是DropDownList
我用SelectedIndexChanged事件,但是选择什么反应都没有,我写的SelectedIndexChanged事件没有运行

急啊!!高手快指点一二....
wacle 2003-08-22
  • 打赏
  • 举报
回复
up is a method to set it's OnSelectedIndexChanged as index_changed to reflect SelectedIndexChaged event,certainly you can write in code-behind like:
private void drop_SelectedIndexChanged(object sender, System.EventArgs e)
{
lbl.Text=drop.SelectedItem.Text;
}
wacle 2003-08-22
  • 打赏
  • 举报
回复
it's SelectedIndexChanged. and you should set dropdownlist's AutoPostBack property as true.
forexample:
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>

<html>
<script language="C#" runat="server">

ICollection CreateDataSource() {
DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
dt.Columns.Add(new DataColumn("DateTimeValue", typeof(DateTime)));
dt.Columns.Add(new DataColumn("BoolValue", typeof(bool)));
dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));

for (int i = 0; i < 9; i++) {
dr = dt.NewRow();

dr[0] = i;
dr[1] = "Item " + i.ToString();
dr[2] = DateTime.Now;
dr[3] = (i % 2 != 0) ? true : false;
dr[4] = 1.23 * (i+1);

dt.Rows.Add(dr);
}

DataView dv = new DataView(dt);
return dv;
}

void Page_Load(Object sender, EventArgs e) {
if (!IsPostBack) {
RadioButtonList1.DataSource = CreateDataSource();
RadioButtonList1.DataTextField="StringValue";
RadioButtonList1.DataValueField="CurrencyValue";
RadioButtonList1.DataBind();
}
}

void Index_Changed(Object sender, EventArgs e) {

Label1.Text = "You selected " + RadioButtonList1.SelectedItem.Text +
" with a value of $" + RadioButtonList1.SelectedItem.Value +
".";

}

</script>

<body>

<form runat=server>

<asp:RadioButtonList id="RadioButtonList1"
OnSelectedIndexChanged="Index_Changed"
AutoPostBack="true"
runat="server"/>

<br>

<asp:Label id="Label1" runat="server"/>

</form>

</body>
</html>
thp 2003-08-22
  • 打赏
  • 举报
回复
SelectedIndexChanged
thp 2003-08-22
  • 打赏
  • 举报
回复
SelectedIndexChanged

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧