Jquery UI Multiselect Widget using Selected Text

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sadasmitabiswal
    New Member
    • Oct 2012
    • 1

    Jquery UI Multiselect Widget using Selected Text

    I am using Jquery UI Multiselect Widget to populate data from database on click of control.But the data from database is coming as System.Data.Dat aRowView in all checkboxes.How to populate real data from database.

    My code is

    Code:
    <head>
      <script type="text/javascript">
    
        $(document).ready(function()
          {
         $("#multi").multiselect().multiselectfilter();
          });
      </script> 
    </head> 
    <body> 
      <form id="form1" runat="server"> 
        <select id="multi" runat="server" > 
        </select> 
      </form> 
    </body>


    My .cs code is
    Code:
    protected void Page_Load(object sender, EventArgs e)
        {
            Bind();
        }
        public void Bind()
        {
    
    
            SqlConnection con = new SqlConnection("Data Source=ST0022;Initial Catalog=QuickMove_Globe;User ID=sa;Password=good");
            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();
            da.SelectCommand = new SqlCommand("Select Name from Sales.ProspectiveLead", con);
            con.Open();
            da.SelectCommand.ExecuteNonQuery();
            da.Fill(ds);
            con.Close();
    
           multi.DataSource = ds.Tables[0];
           multi.DataBind();
    
    
        }
    Last edited by Frinavale; Oct 29 '12, 02:27 PM. Reason: Formatted code so that we can read it more easily.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    That is because you are binding the rows to the select element. When you do this the ToString method is called on the object so that it can be displayed in the control. By default, object's ToString methods return the name of the object.

    So you need to specify which column in the DataRow should be used to display as text in the select element's options, and which column in the DataRow should be used as the "value" selected.

    Something like:
    Code:
    multi.DataTextField = "col_1";
    multi.DataValueField = "col_2";
    multi.DataSource = ds.Tables[0];
    multi.DataBind();
    Check out this MSDN article about the HtmlSelect Class for information about how to accomplish this...

    -Frinny

    Comment

    Working...