如题!    
        private void BindData()
        {
            string orderItemID = "202";//Request.QueryString["orderid"].ToString();
            DataTable dt = SQLData.OrderItem.getDataTable(" OrderId=" + orderItemID);
            rpChangeAddress.DataSource = dt;
            rpChangeAddress.DataBind();
        }
        protected void rpChangeAddress_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            DropDownList ddlList = (DropDownList)e.Item.FindControl("ddlList");
            DataTable dt = SQLData.MemberAddress.GetDataTableAddresslist(4);
            ddlList.DataSource = dt;
            ddlList.DataTextField = "address";
            ddlList.DataValueField = "ID";
            ddlList.DataBind();
        }
        protected void imgBtnDone_Click(object sender, ImageClickEventArgs e)
        {
            string id = "";
            foreach (RepeaterItem RI in this.rpChangeAddress.Items)
            {                Literal literID = RI.FindControl("literID") as Literal;
                DropDownList ddlList = RI.FindControl("ddlList") as DropDownList;
                string orderItemID = literID.Text.Trim();
                string strAddress = ddlList.SelectedItem.Text;
                //common.OrderCarOperate.WriteOrderCar(productID, numbers);
                id += orderItemID + strAddress + "|";            }
            Response.Write(id);
        }后台这样写的  为什么点击按钮得到得是dropdownlist的第一个选项 不是选中的选项!
我要怎么写才能 在点击按钮的时候得到dropdownlist的选中的值!

解决方案 »

  1.   

    如果是在page_load调用了databind(),放在
    if(!IsPostback)
    {}
      

  2.   

    你这个imgBtnDone是在Repeate里面还是外面的???
      

  3.   


    應該是從新綁頂了次
    再不行
    你把selectedItem改成這個試試
      string strAddress = ddlList.SelectedValue; 
      

  4.   

    imgBtnDone是在Repeate里面还是外面的??? 
    是在Repeate外面的
      

  5.   

    应该这样:
    protected void imgBtnDone_Click(object sender, ImageClickEventArgs e) 

            string id = ""; 
            for (int i = 0; i < Repeater1.Items.Count; i++)
            {
                DropDownList ddlList = (DropDownList)Repeater1.Items[i].FindControl("DropDownList1");
                for (int j = 0; j < ddlList.Items.Count; j++)
                {
                    if (ddlList.Items[j].Selected == true)
                        id += ddlList.SelectedItem + "|";
                }
            }
            Response.Write(id); 
    }
      

  6.   

    还是一个德行啊   就能取出第一行的值!
                if (!Page.IsPostBack)
                {
                    BindData();            }
    已经是这样绑定了啊   !
    到底怎么回事啊!
      

  7.   

     autopostBack 勾上了么?
      

  8.   

    估计应该是绑定下拉列表的绑定方法没放Ispostback里  所以你每次触发一服务器控件 就重新加载了。所以每次取的值都是下拉列表的第一个  改进方法: 你将绑定dropdownlist的绑定方法放到
    page_load里
    if(!IsPostback)
    {
         //绑定方法
    }
      

  9.   

    dropdownlist 在repeater里面   我就在
            protected void rpChangeAddress_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                DropDownList ddlList = (DropDownList)e.Item.FindControl("ddlList");
                DataTable dt = SQLData.MemberAddress.GetDataTableAddresslist(4);
                ddlList.DataSource = dt;
                ddlList.DataTextField = "address";
              ddlList.DataValueField = "ID";
                ddlList.DataBind();
            }
    这样绑定的!
    你说在
    估计应该是绑定下拉列表的绑定方法没放Ispostback里  所以你每次触发一服务器控件 就重新加载了。所以每次取的值都是下拉列表的第一个  改进方法: 你将绑定dropdownlist的绑定方法放到 
    page_load里 
    if(!IsPostback) 

        //绑定方法 
    }
    要怎么绑定啊?
    急啊