Asp.Net 下拉列表
我在运行时绑定下拉列表,并将数据填充到数据库中。没关系很好。但是如果我想选择特定值并显示在消息框中。它仅显示默认值。
这里我的代码是:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("You have selected " + DropDownList1.SelectedItem.Value);
}
那么我如何在消息框中显示所选值。 我在这里很新。请帮我。
I Bind the Dropdownlist at runtime and data is populated to the database. Its ok Fine. But if i want to select the particular value and display in a message box. It only shows the default value.
Here My code is:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("You have selected " + DropDownList1.SelectedItem.Value);
}
So how can i display the selected value in the message box.
Here i am very new. Please help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题出在您分配
Datasource
的Page_load
事件中。当您单击该按钮时,Page_load
将再次调用,并将再次重新绑定到您的下拉列表。应该是:
The problem is in your
Page_load
event, where you are assigning yourDatasource
. When you click the button,Page_load
will be called again and it will rebind to your dropdown again.It should be: