怎麼取得dropdownlist選中的ID值

把數據庫綁定在dropdownlist中,而後把選中的dropdownlist的項的ID值保存在另外的一個數據庫中.怎麼取得dropdownlist選中的ID值呢??數據庫

this.DropDownList1.Items.Clear();
this.DropDownList1.DataSource = wwddt;
this.DropDownList1.DataTextField = "version_name";
this.DropDownList1.DataValueField = "version_id";
this.DropDownList1.DataBind();

由於顯示的是"version_name"這個字段,我如今是想當選中"version_name"字段的項時,把"version_name"字段對應的"version_id"值存入另外的一個數據庫中.post

答案:this

 string a = dropdownlist.SelectedText;//獲取選中的text
string b = dropdownlist.SelectedValue; //獲取選中的value
int c = dropdownlist.SelectedIndex; //獲取選中的索引

若是你的dropdownlist.datasource是在pageload裏面綁定的話
頗有多是因爲不斷的初始化(不斷的執行dropdownlist.datasource)致使每回都取道的默認值
通常用ispostback來回避這種狀況 blog

相關文章
相關標籤/搜索