JQUERY DROPDOWNCHECKLIST DOENS'T BINDS DATA

Ashish Pandey

Total Post:128

Points:898
Posted by  Ashish Pandey
 1882  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. Sumit Kesarwani

    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

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!