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
{
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
解决方案 »
- 如何在手机网站实现记住用户名和密码功能??!
- win2003+IIS6.0 网站为vs2008编译,使用.NET framework 2.0 项目中使用sdk为3.5 是否可以正确运行?
- 有哪位大哥做过多条件查询,动态添加条件那种的
- 求ascii转化
- 一个提取内容的正则式有个问题,请求朋友们修改一下
- 看到那个面试做登陆的帖子那么火,我也发个我面试遇见的吧,请各位评论~
- .net 商铺选择功能的最优实现思路以及代码
- .net中计时器显示不了时间
- IIS目录配置问题!!!谢谢!!!
- 请教高手
- MYSql使用UDF错误: Error 1126 Can't open shared librar "MyUDF.Dll"
- AJAX for .net 那个控件是 等待状态 有个圆圈在那转直到有结果位置
而且现在我发现 若DropDownList显示的是中文就正常比如PM10 这样就不正常 若换成 “可吸入颗粒” 就可以正常选择了??这是为什么?
我一直这么用
从来没有问题
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)
{ }
}
<%@ 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>
</div>
</form>
</body>
</html>
<!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>
</div>
<div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBwL7x7xWAoznisYGAvHeqq4OAvHeqq4OAvHeqq4OAvHeqq4OAvHeqq4OKvBK6N3l2J2LecMzfj0194LhpDg=" />
</div></form>
</body>
</html>
取值的时候用 DropList_Param.SelectedValue
确实是你说的这个问题 真的把Value去掉后就好了 呵呵
谢谢你
给分