Howto provide form data to a BLL/DAL?

Discussion in 'ASP .Net' started by Froefel, Jul 5, 2007.

  1. Froefel

    Froefel Guest

    I have written a simple DAL that returns a typed list of objects as a
    source for a gridview.
    I also added the necessary paging and sorting plumbing needed when
    binding a gridview to an ObjectDataSource. That part is working fine.

    However, the next step is to provide a search button to only populate
    the grid on demand (not on pageload) and provide a few web controls
    that drive the search criteria. I'm stuck on both of these tasks.

    Currently, in my aspx page, the ObjectDataSource is defined as
    follows:
    <asp:ObjectDataSource
    ID="productsDataSource"
    runat="server"
    TypeName="ProductDAL"
    SelectMethod="GetProducts"
    SelectCountMethod="TotalNumberOfProducts"
    SortParameterName="SortExpression"
    StartRowIndexParameterName="startRowIndex"
    MaximumRowsParameterName="maximumRows"
    EnablePaging="true">
    </asp:ObjectDataSource>

    Note: The code-behind file doesn't contain any code.

    The ProductDAL looks as follows:
    public class ProductDAL
    {
    private readonly static string connString =
    ConfigurationManager.ConnectionStrings["NWConnectionString"].ConnectionString;

    public static List<Product> GetProducts()
    {
    return GetProducts(int.MaxValue, 0, string.Empty);
    }

    public static List<Product> GetProducts(int maximumRows, int
    startRowIndex)
    {
    return GetProducts(maximumRows, startRowIndex, string.Empty);
    }

    public static List<Product> GetProducts(string SortExpression)
    {
    return GetProducts(int.MaxValue, 0, SortExpression);
    }

    public static List<Product> GetProducts(int maximumRows, int
    startRowIndex, string SortExpression)
    {
    // returns a list of Product instances based on the
    // data in the Northwind Products table
    string sql = @"SELECT ProductID, ProductName, QuantityPerUnit,
    UnitPrice, UnitsInStock FROM Products";
    if (SortExpression != string.Empty)
    sql += " ORDER BY " + SortExpression;

    //here we're using Microsoft's DAAB objects.
    SqlDataReader dr = SqlHelper.ExecuteReader(connString,
    CommandType.Text, sql);
    List<Product> results = new List<Product>();
    int itemsRead = 0;
    int currentIndex = 0;
    while (dr.Read() && itemsRead < maximumRows)
    {
    if (currentIndex >= startRowIndex)
    {
    Product product = new Product();
    product.ProductID = Convert.ToInt32(dr["ProductID"]);
    product.ProductName = dr["ProductName"].ToString();
    product.QuantityPerUnit = dr["QuantityPerUnit"].ToString();
    if (dr["UnitPrice"].Equals(DBNull.Value))
    product.UnitPrice = 0;
    else
    product.UnitPrice = Convert.ToDecimal(dr["UnitPrice"]);
    if (dr["UnitsInStock"].Equals(DBNull.Value))
    product.UnitsInStock = 0;
    else
    product.UnitsInStock = Convert.ToInt32(dr["UnitsInStock"]);
    results.Add(product);
    itemsRead++;
    }
    currentIndex++;
    }
    return results;
    }

    public static int TotalNumberOfProducts()
    {
    return GetProducts().Count;
    }
    }

    Based on the above code, how do I provide the SelectedValue of say a
    DropDownList to the GetProducts function so it can adjust the SQL
    accordingly. Note that all of the criteria controls need to be
    optional (i.e. selecting [All] in a control excludes the criteria).
    Also I need to take into account that one of the criteria controls is
    a multi-select ListBox which should result in an IN(a,b,c) clause in
    the SQL statement.

    Being very new at web development with ASP.NET, I've been puling my
    hair out on how to accomplish this, so any help would be greatly
    appreciated.

    -- Hans
    Froefel, Jul 5, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    1,353
    sloan
    Jun 15, 2006
  2. Roy

    BLL and DAL.

    Roy, Jun 15, 2006, in forum: ASP .Net
    Replies:
    10
    Views:
    17,603
    =?Utf-8?B?Q2hyaXM=?=
    Jun 16, 2006
  3. Nemisis

    DAL or BLL? How to implement objects

    Nemisis, Oct 3, 2006, in forum: ASP .Net
    Replies:
    22
    Views:
    1,646
    Joerg Jooss
    Oct 17, 2006
  4. sloan
    Replies:
    0
    Views:
    430
    sloan
    Dec 5, 2006
  5. sloan
    Replies:
    1
    Views:
    750
    Mark Rae
    Dec 5, 2006
Loading...

Share This Page