Salve a tutti e ben ritrovati
Ho il seguente problema:
un listvievw
<asp:ListView ID="listview1" runat="server" DataSourceID="LinqDataSource1" >
<LayoutTemplate>
<table runat="server" border="1" cellpadding="0" cellspacing="0">
<tr>
<th>Prodotto</th>
<th>Fornitore</th>
<th>Categoria</th>
</tr>
<tr id="itemPlaceholder" runat="server" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="item" runat="server" >
<td ><%# Eval("ProductName")%></td>
<td><%# Eval("Supplier.CompanyName")%></td>
<td><%# Eval("Category.CategoryName")%></td>
</tr>
</ItemTemplate>
</asp:ListView>
una textbox per filtrare il "ProductName" una dropdownlist per filtrare CategoryID: in particolare dropdownlist e così congegnata:
<asp:DropDownList ID="DropDownList1" runat="server"
AppendDataBoundItems="True" DataSourceID="LinqDataSource2"
DataTextField="CategoryName" DataValueField="CategoryID">
<asp:ListItem Value="" Text="Tutte" />
</asp:DropDownList>
ora nel linqdatasource il filtro dovrebbe tenere conto del fatto che potrei non inserire alcun valore nei due controlli quindi mi aspettavo che questo funzionasse:
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="NorthwindDataContext" TableName="Products"
Where="ProductName.contains(@ProductName) && CategoryID==
(@CategoryID??CategoryID)">
<WhereParameters>
<asp:ControlParameter ControlID="TextBox1" Name="ProductName"
PropertyName="Text" Type="String"
ConvertEmptyStringToNull="false" />
<asp:ControlParameter ControlID="DropDownList1" Name="CategoryID"
PropertyName="SelectedValue" Type="Int32" />
</WhereParameters>
</asp:LinqDataSource>
ma la nuova funzione di coalesce per i valori null della dropdownlist in c#, messa in linea nel where, da errore mentre se opero la seguente modifica riesco a far funzionare il tutto
x la ddl
<asp:ListItem Value="-1" Text="Tutte" />
x la calusola where
CategoryID==(@CategoryID==-1)?CategoryID:@CategoryID)
la soluzione xò è sicuramente meno pulita e vorrei evitare di scrivere codice a runtime nel'evento selecting del linqdatasource
qualche idea?
Modificato da papercard il 02 marzo 2009 15.58 -
Modificato da papercard il 02 marzo 2009 15.58 -
Modificato da papercard il 02 marzo 2009 15.59 -