日期:2014-05-19  浏览次数:20749 次

DropDownList动态绑定的数据无法读出
DropDownList动态绑定的数据无法读出,只能读出第一个的数据
程序如下:
        protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                DataSet   TempDs2   =   DatabaseOp.ReturnDataSet(SelectCityCommand2);
                DropDownList1.DataSource   =   TempDs2.Tables[0];
                DropDownList1.DataTextField   =   "cityname ";
                DropDownList1.DataValueField   =   "threecode ";
                DropDownList1.DataBind();
        }
        protected   void   Button1_Click(object   sender,   EventArgs   e)
        {
                Label1.Text   =   DropDownList1.SelectedValue+DropDownList1.SelectedIndex.ToString().Trim();
        }

------解决方案--------------------
晕!

咳 我测试了 半天 终于发现了问题
protected void Page_Load(object sender, EventArgs e)
说明这是 在 B/S 里面
所以要加上 if(!Page.IsPostBack())
{
绑定();
}
否则 点击提交按钮 ,又被 初始化了..

但是 在 C/S 里面 不会出现这种情况