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:
- In the Databound event of the ListBox, insert a ListItem at position 0 with text 'ALL' and value '%'
Arrange your datasource (in my case SQLDataSource) to include the following condition:
[ColumnName] LIKE @ColumnName
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
2010-03-17 16:55:14
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
2010-03-19 00:23:39
Never mind, found it. its insert instead of add
JaSk
2010-03-19 00:29:02