如何DropDownList的选定值绑定 [英] How to bind the selected value of a DropDownList
问题描述
数据绑定是所有关于声明code,对不对?所以,我指定我想与属性,而框架负责其余的照顾。除非我弄错和数据绑定涉及S&安培;男,右
Data binding is all about declarative code, right? So I specify what I want with attributes, and the framework takes care of the rest. Unless I'm mistaken and data binding relates to S&M, right?
那么,为什么DropDownList控件只提供它的数据源,即其名单来源,而不是其实际的数据字段绑定字段。即如何赫克我绑定选定值我的名字DropDownList的名称字段在我的个人记录?这是微软的一大疏忽,还是我的?
So, why does the DropDownList control only provide binding fields for its data source, i.e. its list source, and not for its actual data field. i.e. how the heck to I bind the selected value my name DropDownList to the Name field in my Person record? Is this a gross oversight on Microsoft's part, or on mine?
什么是双向数据绑定,如果我仍然需要手工设置和读取所选值?点
What is the point of two way data binding if I still have to manually set and read the selected value?
推荐答案
您可能想要做的东西像下面的code。
你不能设置的SelectedValue声明,但说
的SelectedValue =<%#[code这里]%>你实际上造成当控件的数据势必要设置的值
You might want to do something like the code below. You can not set the "SelectedValue" declaratively, but by saying "SelectedValue=<%# [code here] %> you are effectively causing the value to be set when the control is data bound.
<asp:DropDownList
ID="DropDownInfoSource"
runat="server"
DataSourceID="_employeeDataSource"
DataTextField="EmployeeName"
DataValueField="EmployeeID"
SelectedValue='<%# Bind("EmployeeID") %>'
/>
这篇关于如何DropDownList的选定值绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!