JaSk
JaSk

Reputation: 107

Databind listbox

I'm pretty new to asp net 2.0 programming and I was wondering how can I add an "all" item to a listbox, so I can filter my results by a specific criteria ( from a database ) or display all the results. Thanks in advance

Upvotes: 0

Views: 362

Answers (1)

Matthew Jones
Matthew Jones

Reputation: 26190

One solution is to modify the DataSource of the control that relies on the selection in the ListBox:

  1. In the Databound event of the ListBox, insert a ListItem at position 0 with text 'ALL' and value '%'
  2. Arrange your datasource (in my case SQLDataSource) to include the following condition:

    [ColumnName] LIKE @ColumnName

  3. Add a Parameter to the DataSource for the object that depends on the selection in the ListBox:

    <asp:ControlParameter ControlID="ListBoxID" Name="ColumnName" PropertyName="SelectedValue" />

Upvotes: 1

Related Questions