按钮里取不到listbox选中的值,老是出现默认的值

解决方案 »

  1.   

    不会啊,你要找对方法啊有一个属性可以获取或设置listbox当前值,我忘了,你仔细找找吧。。
      

  2.   

    先点击listbox 在它的属性里找到text把text里面的数据清空掉,然后在后台代码比如说  textbox 来获取listbox中选中的值就这样写,textbox = listbox.Text;就OK了
      

  3.   

    贴代码出来,,,看看到底什么情况string strValue = ListBox1.SelectedItem.Value;//这就是ListBox选中的值
      

  4.   

    for(int i=0;i<ListBox1.Items.Count;i++ )
      {
      if (ListBox1.Items[i].Selected) Response.Write(ListBox1.Items[i].Text);
      } 
     
    listBox1.SelectedItem.ToString()
      

  5.   

    page_load 事件代码中
    要加上
    if(!IsPostBack)
    {
      你原有的代码
    }
      

  6.   


    if (!IsPostBack)
            {
    绑定checkboxlist的代码
    }
    protected void btn_Click(object sender, EventArgs e)
        {
              ListBox1.SelectedValue.ToString();///取到的是默认的值,也就是是第一个值
    }
      

  7.   

      protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    ListBox1.Items.Clear();
                    ListItem li = new ListItem("A","1");
                    ListBox1.Items.Add(li);
                    ListItem lii = new ListItem("B", "2");
                    ListBox1.Items.Add(lii);
                    
                }
            }        protected void Button1_Click(object sender, EventArgs e)
            {
                string value = ListBox1.SelectedValue.ToString();
            }我可以获得啊