文本框 (RadTextBox) 应该通过使用 ObjectDataSource 的 FilterExpression 来过滤 ListView (RadListView)。ObjectDataSource 的基础数据源是 WCF 服务。
它不工作。在我所有的试验和错误中,我所能得到的只是将整个数据集绑定到 ListView 或根本没有记录。我无法通过从文本框中的输入中筛选出一些记录。
这是一个帮助视频(此时有点绝望......)
提前致谢!
辐射列表视图:
<telerik:RadListView ID="RadListView1" runat="server"
DataSourceID="ObjectDataSource1" AllowPaging="True"
ItemPlaceholderID="ListingsContainer" Width="940px" SkinID="Bootstrap">
对象数据源:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" EnablePaging="true" TypeName="manageListingsController" SelectMethod="GetProducts" StartRowIndexParameterName="startRowIndex"
SelectCountMethod="GetProductsCount" FilterExpression="ItemID = '{0}%'" InsertMethod="InsertProduct" DeleteMethod="DeleteProduct" UpdateMethod="UpdateProduct" OldValuesParameterFormatString="Original_{0}" SortParameterName="sortExpression">
<FilterParameters>
<asp:ControlParameter Name="@ItemID" ControlID="txtItemID" ConvertEmptyStringToNull="false" Type="String" />
</FilterParameters>
<InsertParameters>
<asp:Parameter Name="ItemID" Type="String" />
<asp:Parameter Name="SiteID" Type="Int32" />
<asp:Parameter Name="Price" Type="Decimal" />
<asp:Parameter Name="Quantity" Type="Int32" />
<asp:Parameter Name="ProductID" Type="String" />
<asp:Parameter Name="Condition" Type="String" />
<asp:Parameter Name="ToAP" Type="Boolean" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ItemID" Type="String" />
<asp:Parameter Name="SiteID" Type="Int32" />
<asp:Parameter Name="Price" Type="Decimal" />
<asp:Parameter Name="Quantity" Type="Int32" />
<asp:Parameter Name="ProductID" Type="String" />
<asp:Parameter Name="Condition" Type="String" />
<asp:Parameter Name="ToAP" Type="Boolean" />
<asp:Parameter Name="Original_ID" Type="Int32"></asp:Parameter>
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="ItemID" Type="String" />
<asp:Parameter Name="SiteID" Type="Int32" />
<asp:Parameter Name="Original_ID" Type="Int32"></asp:Parameter>
</DeleteParameters>
</asp:ObjectDataSource>
获取产品方法:
public DataTable GetProducts(int startRowIndex,
int maximumRows,
string sortExpression)
{
ProductsAPI.ProductsClient pCl = new ProductsAPI.ProductsClient();
DataTable n = new DataTable();
try
{
rowCount = temp.Count;
try
{
n = Help.ToDataTable(temp.ProductData.ToList());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(null, ex);
}
return n;
}
WCF GetProducts 操作合同:
[OperationContract]
public ResultData GetProducts(int startRowIndex, int maximumRows, string sortExpression, string filterExpression)
{
DAL.Products.Products p = DAL.Products.Products.Instance();
return p.GetDataAndCount(startRowIndex, maximumRows, sortExpression, filterExpression);
}
WCF GetDataAndCount 方法:
public ResultData GetDataAndCount(int startRowIndex, int maximumRows, string sortExpression, string filterExpression)
{
//http://demos.telerik.com/aspnet-ajax/grid/examples/data-binding/client-side/declarative/defaultcs.aspx
//http://demos.telerik.com/aspnet-ajax/listview/examples/client/webservicedatabinding/defaultcs.aspx
GridLinqBindingData<v_mp_GenListings_Data> data = RadGrid.GetBindingData(
(new Entities()).v_mp_GenListings_Data.OrderByDescending(p => p.ProductID),
startRowIndex, maximumRows, sortExpression, filterExpression);
ResultData result = new ResultData();
result.ProductData = data.Data.OfType<v_mp_GenListings_Data>().Select(p => new Product()
{
ItemID = p.ItemID,
SKU = p.SKU,
ID = p.ID,
SiteID = p.SiteID,
MarketPlaceType = p.MarketplaceType,
SiteName = p.SiteName,
//AccOverride = p.AccOverride,
//ToAP = p.ToAP,
//CeilingPriceFixed = p.CeilingPriceFixed,
//Min = p.Min,
NightModeID = p.NightModeID,
NightModeCode = p.NightModeCode,
ToMAP = p.ToMAP,
ConditionID = p.ConditionID,
MerchantID = p.MerchantID,
ProductID = p.ProductID,
Quantity = p.Quantity,
Price = p.Price,
URL = p.URL
}).ToList();
result.Count = data.Count;
return result;
}