public partial class temp_Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.DropList_Param.DataSource = ClassDB.ExecuteSql("select top 10 Date_Time ,Value1 from s001t15 order by Date_Time desc", "");
            this.DropList_Param.DataTextField = "Date_Time";
            this.DropList_Param.DataValueField = "Value1";
            this.DropList_Param.DataBind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {    }
}这样写因该没错吧 几百年前就知道要写在(!Page.IsPostBack)可以现在我碰到的问题是 每次按BUTTON1后DropDownList 的值又会到第一个选项了???而且是有时候会有时候又不会 这是怎么回事???? 就是说比如我选择的是 第3项及过递交后得到的还是第一项,但有时又真正这是怎么回事??
用的是VS2005

解决方案 »

  1.   

    页面里是不是还有其它的代码?是不是直接访问的temp_default3.aspx这个页?把所有多余的代码都去掉再试
      

  2.   

    没其他代码了 真是故意做了一个最简单的页面 
    而且现在我发现 若DropDownList显示的是中文就正常比如PM10 这样就不正常 若换成 “可吸入颗粒” 就可以正常选择了??这是为什么?
      

  3.   

    把!Page.IsPostBack改成this.IsPostBack看看
    我一直这么用
    从来没有问题
      

  4.   

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;public partial class temp_Default3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                //this.DropList_Param.DataSource = ClassDB.ExecuteSql("SELECT [Area_Type], [Area_Name] FROM [Enview].[dbo].[Area]", "");
                this.DropList_Param.DataSource = ClassDB.ExecuteSql("SELECT  [Name],[Unit] FROM [Enview].[dbo].[Param_List] where PType=1", "");
                this.DropList_Param.DataTextField = "Name";
                this.DropList_Param.DataValueField = "Unit";
                this.DropList_Param.DataBind();
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {    }
    }
      

  5.   

    编码问题?把生成的HTML代码也贴上来看看
      

  6.   

    Button1_Click中的也贴出来看看!
      

  7.   

    下面是编码 谢谢大家
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="temp_Default3" %><!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>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
            <asp:DropDownList ID="DropList_Param" runat="server" AppendDataBoundItems="True">
            </asp:DropDownList>&nbsp;
        </div>
        </form>
    </body>
    </html>
      

  8.   

    把这个属性去了试试AppendDataBoundItems,这个的默认值是False
      

  9.   

    一样的 True 和 False 都用过了 没没效果
      

  10.   

    生成的HTML代码呢?就是在浏览器里查看源文件看到的
      

  11.   

    这是原文件
    <!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><title>
    无标题页
    </title></head>
    <body>
        <form name="form1" method="post" action="Default3.aspx" id="form1">
    <div>
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTQ0OTUxOTQxNA9kFgICAw9kFgICAw8QDxYGHg1EYXRhVGV4dEZpZWxkBQROYW1lHg5EYXRhVmFsdWVGaWVsZAUEVW5pdB4LXyFEYXRhQm91bmRnZBAVBRfmu7Tlrprms5VQTTEwICAgICAgICAgIBflo6vlpKflpKtTTzIgICAgICAgICAgIBbmmK/lkKZDTyAgICAgICAgICAgICAgFuaUtui0uU8zICAgICAgICAgICAgICAV5LiKIE5PMiAgICAgICAgICAgICAgFQUUbWcvTCAgICAgICAgICAgICAgICAUbWcvTCAgICAgICAgICAgICAgICAUbWcvTCAgICAgICAgICAgICAgICAUbWcvTCAgICAgICAgICAgICAgICAUbWcvTCAgICAgICAgICAgICAgICAUKwMFZ2dnZ2dkZGSfSUpPYb6V3GEnt+A3xCgd4MQQSg==" />
    </div>    <div>
            <input type="submit" name="Button1" value="Button" id="Button1" />
            <select name="DropList_Param" id="DropList_Param">
    <option selected="selected" value="mg/L                ">滴定法PM10          </option>
    <option value="mg/L                ">SO2           </option>
    <option value="mg/L                ">CO              </option>
    <option value="mg/L                ">O3              </option>
    <option value="mg/L                ">NO2              </option></select>&nbsp;&nbsp;
        </div>
        
    <div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBwL7x7xWAoznisYGAvHeqq4OAvHeqq4OAvHeqq4OAvHeqq4OAvHeqq4OKvBK6N3l2J2LecMzfj0194LhpDg=" />
    </div></form>
    </body>
    </html>
      

  12.   

    你的VALUE都是一样的,所以你选哪个都是一样的!你的BUTTON_CLICK里面肯定取的是selectedvalue!如果你的VALUE绑定以后确实是这样,只能通过别的来判断!
      

  13.   

    AppendDataBoundItems="True" 去掉
    取值的时候用 DropList_Param.SelectedValue
      

  14.   


    确实是你说的这个问题 真的把Value去掉后就好了 呵呵
    谢谢你
    给分