開始覺得asp:DropDownList數據綁定要是datatable類型的,當時寫的時候沒注意,就寫成了List<T>綁定到了dropdownlist上,結果只有將DataValueField和DataTextField這兩個屬性設置到相應的列上,數據一樣能夠完成綁定。ide
下面貼出綁定的流程:this
後臺代碼:server
protected void Page_Load(object sender, EventArgs e)pdo
{string
if (!IsPostBack)it
{table
this.name2.DataSource = 數據源;class
this.name2.DataValueField = "列名";後臺
this.name2.DataTextField = "列名";object
this.name2.DataBind();
}
}
public void Name2_Changed(object sender, EventArgs e)
{
//選項變時的代碼實現
//獲取當前選項值 string df = this.name2.SelectedValue;
}
前臺代碼:
<asp:DropDownList runat="server" ID="name2" OnSelectedIndexChanged="Name2_Changed"></asp:DropDownList>