views:

47

answers:

1

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

+1  A: 

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" />

Matthew Jones
Perfect, can you please give me an example of how to add it at position 0 in the databound event?I did this:protected void txtCiudad_DataBound(object sender, EventArgs e){ txtCiudad.Items.Add(new ListItem("Todas", "%"));}but I can't define the index. thanks
JaSk
Never mind, found it. its insert instead of add
JaSk