Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

122
Vistas
Not getting Name and Id together when Jquery Chosen property used in ASP.NET

I am using jquery chosen property to style asp:Dropdownlist in my project.I am following existing project. In that the drop down is populated with below code.

Supporting jquery files:

 <script type="text/javascript" src="../Scripts/jquery-3.4.1.min.js"></script>  
    <script src="../Scripts/jquery-1.9.1.js" type="text/javascript"></script>
    <script src="../scripts/chosen.jquery.min.js" type="text/javascript"></script>
      <link href="../styles/chosen.min.css" rel="stylesheet" type="text/css" />
    <link href="../Styles/jquery-ui.css" rel="stylesheet" />
    <script type="text/javascript" src="../Scripts/jquery-ui.js"></script>

Dropdown code at frontend:

<asp:DropDownList ID="dropdown" TabIndex="28" CssClass="chosen-default" AutoPostBack="true"
OnSelectedIndexChanged="dropdown_selectedIndexChanged" runat="server">
</asp:DropDownList>

dropdown populated at backend with table result:

dropdown.DataSource = objResult.Tables[6].DefaultView;
dropdown.DataTextField = objResult.Tables[6].Columns["Name"].ToString();
dropdown.DataValueField = objResult.Tables[6].Columns["Id"].ToString();
dropdown.DataBind();

And chosed function is used for this dropdown to style it.

        $(function () {
            $('#dropdown').chosen();
        });

And the result is like this image. List is having Name followed by Id in breckets.

we are also following the same But only Name is getting displayed in the dropdown list. Id is not displayed. Please help.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Besides the fact, that you are loading jQuery in different version multiple times, you can simply build the string you want:

dropdown.DataTextField = $"{objResult.Tables[6].Columns["Name"].ToString()} ({objResult.Tables[6].Columns["Id"].ToString()})";

or to make it easier to read:

var name = objResult.Tables[6].Columns["Name"].ToString();
var id = objResult.Tables[6].Columns["Id"].ToString();
dropdown.DataTextField = $"{name} ({id})";
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda