我把dropdownlist的动态绑定数据库里的一个字段,并放在了if(!postbackpost)中,代码如下:
private void Page_Load(object sender, System.EventArgs e)
{
 if(!Page.IsPostBack)
{
   Bindddlsymc();//droplist绑定了数据库中的一个字段

}
     Label1.Text="You chose: " +ddlsymc.SelectedItem.Text;  
                   }
label1用来显示我选择的项,但是无论我选哪一项,label1显示的都是dropdownlist默认的第一项?
对dropdownlist的Autopostback属性无论是true还是false都是一样的结果
这到底是为什么?求求各位大哥大姐救我!

解决方案 »

  1.   

    Label1.Text="You chose: " +ddlsymc.SelectedItem.Text;  
    将这条语句放到dropdownlist的selectchange事件中去吧
      

  2.   

    to egonzou:
    结果也是一样的,我试过了,还有什么办法吗?先谢谢了
      

  3.   

    private void dropdownlist_SelectedIndexChanged(object sender, System.EventArgs e)
    {
       Label1.Text="You chose: " +ddlsymc.SelectedItem.Text;  
    }
      

  4.   

    DropDownList1.SelectedIndex=DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText(e.Item.Cells[8].Text.ToString().TrimEnd())); 
    寫可以了﹐我這么用
      

  5.   

    to szdugeng:
    (!Page.IsPostBack)  有誤?
    能不能详细一点?
      

  6.   

    private void Page_Load(object sender, System.EventArgs e)
    {
        if(!Page.IsPostBack)
        {
     Bindddlsymc();//droplist绑定了数据库中的一个字段

        }

    //在ddlsymc事件中
    private void ddlsymc_SelectedIndexChanged(object sender, System.EventArgs e)
    {
         string strCon=ddlsymc.SelectedItem.Text.Trim ();//pda号码
         Label1.Text="You chose: " +strCon;
    }
      

  7.   

    to conan19771130:
    这样的话我的绑定数据库在页面重载时都要刷新了,那绑定的肯定也是默认的第一个字段了!
      

  8.   

    to weiqj8686:
    我按你的方法去做了,结果都是一样的,5555,我快急死了!:<
      

  9.   

    你看看InitializeComponent方法里面事件有没有绑定到方法上,还后就是DropDownList的Autopostback属性要设置成true
    private void InitializeComponent()
    {    
    this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
    this.Load += new System.EventHandler(this.Page_Load);
    }private void Page_Load(object sender, System.EventArgs e)
    {
    if (!Page.IsPostBack)
    {
    Bindddlsymc();
    this.Label1.Text = this.DropDownList1.SelectedItem.Text;
    }
    } private void Bindddlsymc()
    {
    for(int i=0; i<10; i++)
    this.DropDownList1.Items.Add(i.ToString());
    } private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    this.Label1.Text = this.DropDownList1.SelectedItem.Text;
    }
      

  10.   

    to pupo:
    InitializeComponent方法里面事件我有绑定到方法上呀,DropDownList的Autopostback属性设置成true了,还是不行?
      

  11.   

    如果还是不行的话,可能是你的机器有问题.
    还有就是在DropDownList选择后它有没有提交页面,如果没提交的话,可能是aspnet_client里面的文件出问题了,我也曾经碰到过点击按纽不提交,后面覆盖了一下aspnet_client里面的文件就好了
      

  12.   

    问题解决了,正如xiaomatian老兄所说的重新建了个页面,代码我一摸一样的copy过去,哈哈,居然行了,真是想不明白.
    谢谢各位兄台,结帐,散分!虽然不多!哈哈!
      

  13.   

    if(!Page.IsPostBack)
    {
       ddlsymc.SelectedIndex=ddlsymc.Items.IndexOf(ddlsymc.Items.FindByText('字段名稱'));;//droplist绑定了数据库中的一个字段}
         Label1.Text="You chose: " +ddlsymc.SelectedItem.Text;  
                       }