jQuery dropdownchecklist doesn't binds data

Total Post:128

Points:898
JQuery 
 2359  View(s)
Ratings:
Rate this:

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: enter image description here

When I run the program my DDLProjectDetails doesn't shows that has any items.

  1. Post:378

    Points:2694
    Re: jQuery dropdownchecklist doens't binds data

    Hi Ashish, 


    string conStr = YOUR_CON_STR;

    using (SqlConnection con = new SqlConnection(conStr))

    {

        SqlCommand com = new SqlCommand("SELECT [idBenutzer], [benutzerName], [aktiv] FROM [Benutzer]", con);

        con.Open();

        SqlDataReader rdr = com.ExecuteReader();

        DropDownList1.DataBind(); // NECESSARY

        while (rdr.Read())

        {

            Debug.WriteLine(rdr.GetInt32(0) + " " + rdr.GetString(1) + " " + rdr.GetBoolean(2));

            if (DropDownList1.Items.Contains(DropDownList1.Items.FindByValue(rdr.GetInt32(0).ToString())))

            {/* do anything */ }

        }

    }

Answer