无法从下拉列表中获取值 [英] Cannot get the value from the drop down list

查看:70
本文介绍了无法从下拉列表中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用DisplayBusRouteID()从数据库中分配项目。当我使用ddlLocation_SelectedIndexChanged()方法从ddlLocation中选择项时,lblBusTicketPrice不起作用。有什么问题?



I use DisplayBusRouteID() assign item from the database. When I use ddlLocation_SelectedIndexChanged() method to select the item from the ddlLocation, the lblBusTicketPrice does not work. What is the problem ?

protected void DisplayBusRouteID()
{
   DataClassesDataContext db = new DataClassesDataContext();

   var query = from s in db.BusRoutes
         select s;

   ddlLocation.DataSource = query;
   ddlLocation.DataTextField = "BusRouteID";
   ddlLocation.DataBind();
       
}
 protected void ddlLocation_SelectedIndexChanged(object sender, EventArgs e)
{
   lblBusTicketPrice.Text = "abc";
}

推荐答案

设置
autopostback="true"

下拉菜单... :)



of dropdown...:)

protected void DisplayBusRouteID()
{
   DataClassesDataContext db = new DataClassesDataContext();
 
   var query = from s in db.BusRoutes
         select s;
 
   ddlLocation.DataSource = query;
   ddlLocation.DataTextField = "BusRouteID";
  ddlLocation.DataValueField = "BusRouteID";
   ddlLocation.DataBind();
       
}
 protected void ddlLocation_SelectedIndexChanged(object sender, EventArgs e)
{
   lblBusTicketPrice.Text = "abc";
}


确保您的dropdownlist标签具有属性 AutoPostBack =true和页面加载方法如下..

make sure your dropdownlist tag has the attribute AutoPostBack="true" and page load method as below..
<asp:dropdownlist id="ddlLocation" autopostback="true" runat="server" onselectedindexchanged="ddlLocation_SelectedIndexChanged" xmlns:asp="#unknown"></asp:dropdownlist>













protected void Page_Load(object sender, EventArgs e)
       {
           if (!Page.IsPostBack)
           {
               // make sure all your initialisation andloading methods are called is in this block.
               // not outside this block

           }
       }</pre>


将ddlLocation的autopostback属性设置为true



Set autopostback property of ddlLocation to true

<asp:DropDownList ID="ddlLocation" runat="server" AutoPostBack="True"                onselectedindexchanged="ddlLocation_SelectedIndexChanged">
</asp:DropDownList>


这篇关于无法从下拉列表中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆