我正在尝试从列表中按值绑定(选择)一些数据,但这是不可能的。
如您所见,我按此值存储它们:
DataValueField="ID_PROJECT_TYPE_DETAILS"
我有以下html代码:
<asp:ListBox SelectionMode="Multiple" ID="DDLProjectDetails" runat="server"
DataSourceID="SqlDataSource4" DataTextField="DESCRIPTION"
DataValueField="ID_PROJECT_TYPE_DETAILS">
</asp:ListBox>
<script type="text/javascript">
$(document).ready(function () {
$('#<%= DDLProjectDetails.ClientID %>').dropdownchecklist({ width: 248 });
});
</script>
<asp:SqlDataSource ID="SqlDataSource4" runat="server"
ConnectionString="<%$ ConnectionStrings:MesarchConnectionString %>"
SelectCommand="SELECT * FROM [PROJECT_TYPE_DETAILS]"></asp:SqlDataSource>
和代码背后的代码:
string insCmd = "SELECT ID_PROJECT, ID_PROJECT_TYPE_DETAILS FROM PROJECT_TYPE_DETAILS_OF_PROJECT WHERE ID_PROJECT = @IDProject";
...
dr = com.ExecuteReader();
while (dr.Read())
{
if (DDLProjectDetails.Items.Contains(DDLProjectDetails.Items.FindByValue(dr.GetInt32(1).ToString())))
DDLProjectDetails.Items.FindByValue(dr.GetInt32(1).ToString()).Selected = true;
}
并且不会像这样填写我的下拉清单:
当我运行程序时,我的 DDLProjectDetails 没有显示有任何项目......