Home > DeveloperSection > Forums > jQuery dropdownchecklist doens't binds data
Ashish Pandey

Total Post:128

Points:898
Posted on    August-28-2014 1:17 AM

 JQuery
Ratings:


 1 Reply(s)
 1488  View(s)
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.



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    August-28-2014 2:12 AM

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 */ }

    }

}


Don't want to miss updates? Please click the below button!

Follow MindStick