
I am trying to bind(select) the some data by value from my list but it is not possible.
As you can see I store them by this value:
DataValueField=”ID_PROJECT_TYPE_DETAILS”
I have the following html code:
<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>
and the code behind code:
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;
}
and doesn’t fills my dropdownchecklist like this:

When I run the program my DDLProjectDetails doesn’t shows that has any items…
Items collection of DDLProjectDetails did not get data bound yet. All you have to do is call DataBind() so that when your code comes to
ExecuteReader() ...Items are already bound.