using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {        SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["conn"]);
        string sql = "select * from wh_hdnr_zj ";
        SqlCommand command = new SqlCommand(sql, conn);
        conn.Open();
        SqlDataReader rs = command.ExecuteReader();
        lb.Items.Clear();
        if (rs.HasRows)
        {
            while (rs.Read())
            {
                ListItem li = new ListItem();
                li.Value = rs["cxlb"].ToString();
                li.Text = "买:" + rs["buymoney"] + rs["cxlb"].ToString();
                lb.Items.Add(li);
            }
        }
        rs.Close();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.
AppSettings["conn"]);
        string cx_qc = qc.Text.Replace("+","");
        string cx_sp = sp.Text.Replace("+","");
        string ks = ksrq.Value.Replace("-","");
        string jz = jzrq.Value.Replace("-","");
        string zjlb = lb.SelectedValue;        string sql = "select * from zj_leiji_mingxi where input_date between '"+ks+"' and '"+
jz+"'and qici='"+cx_qc+"' and pay_sp_bm='"+cx_sp+"' and leibie='"+zjlb+"'";
        SqlCommand command = new SqlCommand(sql, conn);
        conn.Open();
        SqlDataReader rs = command.ExecuteReader();
        if (rs.HasRows)
        {
            while (rs.Read())
            {
                Response.Write("奖品名:" + rs["pay_sp_name"] + "赠奖时间:" 
+ rs["input_time"] +"赠送数量"+rs["pay_num"]+"赠奖人"+rs["fuser"]+"<br/>");
            }      
        }
        else
        {
                Response.Write("没有相关赠奖记录!");
        }
        rs.Close();
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {    }
}lb是dropdownlist的ID现在表 from wh_hdnr_zj  里有两条记录 下拉表也能读出2条记录 "普通赠"和 "贵重赠" 但是提交查询的时候就能 string zjlb = lb.SelectedValue; 就只能收到"普通赠" 而收不到 "贵重赠"  请问是什么原因?

解决方案 »

  1.   

    你怎么学的啊,一点注释没有,怎么看啊,还起名字都很奇怪,全是简写。还有就是,你看看你的下拉框的Autopostback是不是true
      

  2.   

    你的代码问题在于:
    每次选择dropdownlist 页面都会重绑定一次
      

  3.   

    简而言之,把dropdownlist的Autopostback属性设置为false
      

  4.   


    那你怎么触发这个事件?
    DropDownList1_SelectedIndexChanged
      

  5.   

    事件是 用  protected void Button1_Click触发的啊
      

  6.   

    选中的dropdownlist的value只要在button1 click的时候才会 取来 做比较
      

  7.   

    那就在protected void Button1_Click的一行写上drplst.AutoPostBack=true 就OK了
      

  8.   


    这样试了,这样还是显示 “没有相关赠奖记录” 而且刷新后,就只能点选第一项。点其他项也是第一项。if(!IsPostBack)
            {
            string zjlb = lb.SelectedValue;
            }
    你的意思是这样吗?
      

  9.   

    将page_load事件中的代码用
       if(!IsPostBack)
       {
           //绑定DropDownList的代码
       }
    括起来......
      

  10.   

    你这是服务端事件.。 会造成页面刷新.。  刷新了肯定会再次进入page_load事件啊.. 
    page_load的意思就是页面加载事件.。  每次加载都会进的。 进了后你的DropDownList就会重新绑定数据,,而你的数据第一条就是 普通赠,所以你每次点击按钮都会是这第一条数据.。 
    只有 !IsPostBack 就是每次页面只加载一次. 。  
    建议你去了解下页面的运行周期.。