日期:2014-05-18  浏览次数:20353 次

为什么我的DropDownList的选择项总是选择第一个
相当的郁闷……
  源码如下:
  <tr><td style="width: 97px">Order Type:</td>
  <td style="width: 166px">
  <asp:DropDownList ID="Ddl_OrderType" runat="server" Width="150px" OnSelectedIndexChanged="Ddl_OrderType_SelectedIndexChanged" AutoPostBack="true">
  <asp:ListItem Value="19.98">Avatar</asp:ListItem>
  <asp:ListItem Value="19.98">Real Person</asp:ListItem>
  <asp:ListItem Value="19.98">Isocon Dolls</asp:ListItem>
  </asp:DropDownList>
  </td>
  </tr>
  <tr><td style="width: 97px">Price:</td>
  <td style="width: 166px">
  <asp:TextBox ID="txt_Price" runat="server" ReadOnly="true" AutoPostBack="true" Width="111px"></asp:TextBox>dollar
  </td> 
  </tr>
  <tr><td style="width: 97px">Mail Regional:</td>
  <td style="width: 166px">
  <asp:DropDownList ID="Ddl_MailRegional" runat="server" Width="150px" OnSelectedIndexChanged="Ddl_MailRegional_SelectedIndexChanged" AutoPostBack="True">
  <asp:ListItem Value="24.8">North America</asp:ListItem>
  <asp:ListItem Value="24.6">Sourth America</asp:ListItem>
  <asp:ListItem Value="26.5">Sourth America</asp:ListItem>
  <asp:ListItem Value="18.5">Asia</asp:ListItem>
  <asp:ListItem Value="23.5">Oceania</asp:ListItem>
  <asp:ListItem Value="21.9">Africa</asp:ListItem>  
  </asp:DropDownList>
  </td> 
  </tr>
 事件如下:
  protected void Ddl_OrderType_SelectedIndexChanged(object sender, EventArgs e)
  {
   
  txt_Price.Text = Ddl_OrderType.SelectedItem.Value;//动态的加载不同类型订单的价格
  
  
  }
  protected void Ddl_MailRegional_SelectedIndexChanged(object sender, EventArgs e)
  {
  txt_MailingCosts.Text = Ddl_MailRegional.SelectedItem.Value;  
  }
  
  说明:只要页面一刷新,第一个列表总自动选择第一个了。 第二个列表框则我要要选择的,没有变。。。
  郁闷 。我看着两个列表框一样呀?可是为什么会是这样呢?

  高手指点一下吧。。。谢谢了。。。。

------解决方案--------------------
if (!Page.IsPostBack)
{
//DropDownList绑定数据
}
要放在IsPostBack里
------解决方案--------------------
问题所在:
protected void Ddl_OrderType_SelectedIndexChanged(object sender, EventArgs e)
{

txt_Price.Text = Ddl_OrderType.SelectedItem.Value;//动态的加载不同类型订单的价格
 
 

里面要加上对Ddl_OrderType的赋值语句,比如Ddl_OrderType=“2”,那么每次刷新后会看到Ddl_OrderType
里显示的是2
------解决方案--------------------
探讨
if (!Page.IsPostBack)
{
//DropDownList绑定数据
}
要放在IsPostBack里

------解决方案--------------------
曾经有过这样的经过。。。
很难说的清楚。。真郁闷的。。也是没解决

------解决方案--------------------