StudentIT
StudentIT

Reputation: 481

ASP.NET How to display 2 column in dropdownlist?

I use dropdownlist with SQLDataSource to add on dropdownlist. Since there is only 1 DataTextField to display, how can i add second one to it? I want to display description and workprocess on the list, here HTML code,

<asp:DropDownList ID="DropDownWorkProcess" runat="server" DataSourceID="SqlDataSource1" DataTextField="Description" DataValueField="WorkProcess">
    </asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" SelectCommand="SELECT [Description], [WorkProcess] as workprocess FROM [tblWorkProcess]"></asp:SqlDataSource>

If that cannot work, is there other easier simple way from 3rd party such as AJAX Toolkit?

Upvotes: 0

Views: 7163

Answers (2)

Icarus
Icarus

Reputation: 63964

You can't use a dropdown list to achieve this sort of thing since DropDown lists are rendered on the browser as select elements.

You need to use a custom control. People typically use unordered lists (ul) and list items (li) to achieve the behaviour you want.

Telerik controls use that approach - ul and li. See here: http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/multicolumncombo/defaultcs.aspx

Upvotes: 1

xlecoustillier
xlecoustillier

Reputation: 16351

Try concatenating the fields :

SELECT [Description] + ' ' + [WorkProcess] as workprocess FROM [tblWorkProcess]

Upvotes: 1

Related Questions