开发者

How to bind datalist with multiple datasources

Can I bind a datalist with 2 datasource. The scenario is my data list is bound on the design view which displays a list of products, What I want to achieve is, when a user clicks on a side menu filter, the datalist should show the results with respect to that filter click, but I dunno how to disable the previous binding of datalist and bind it with a new datalist depending on the clicked filter option.开发者_C百科


I suggest building a business object between the design view and the data access tier. In the business tier, you can pass a param indicating what the filter is, and act accordingly. Then you simply need to set a default filter and call MyGridView.DataBind() when the filter changes. If this is a web app, this business object might live in

app_code\BLL
    Product.cs

Product.cs would include a "filter" param and the other params needed for the data access tier, e.g., orderBy, rowStart, rowEnd. For example,

public class Product
{
  public List<Product> GetAll(string filter, string orderBy, int startRowIndex, int maximumRows)
  {
    List<Product> products = null;
    switch(filter)
    {
      case "option1":
        // to do: products = some data access call
        break;
      case "option2":
        // to do: products = some other data access call
        break;
      default:
        throw new InvalidOperationException("Unexpected filter option.");
    }
    return products;
  }
}

Your ObjectDataSource would reference the business tier, rather than the data access tier:

<asp:ObjectDataSource
  TypeName="MyAssembly.BLL.Product"
  SelectMethod="GetAll"
  ...
  <SelectParameters>
    <Parameter name="filter"...
    <Paramter name="param1"...

<asp:gridview ...
  DataSourceId="obGridViewSource"

Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜