Пример #1
0
    protected void Grid1_DataSourceNeeded(object sender, GridDataSourceNeededEventArgs e)
    {
        // Preparing the SQL query for populating the Grid
        string sortExpression = "";

        if (string.IsNullOrEmpty(e.SortExpression))
        {
            sortExpression = " ORDER BY ProductID DESC";
        }
        else
        {
            sortExpression = " ORDER BY " + e.SortExpression;
        }

        string query = "SELECT TOP " + e.MaximumRows.ToString() + " * FROM (SELECT ProductID, CategoryID, ProductName, UnitPrice FROM Products";

        if (e.StartRowIndex != 0)
        {
            query += " WHERE ProductID NOT IN (SELECT TOP " + e.StartRowIndex.ToString() + " ProductID FROM Products" + sortExpression + ")";
        }
        query += sortExpression;
        query += ")";

        // Extracting the rows
        OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../App_Data/Northwind.mdb"));
        OleDbCommand    myComm = new OleDbCommand(query, myConn);

        myConn.Open();
        OleDbDataAdapter da = new OleDbDataAdapter();
        DataSet          ds = new DataSet();

        da.SelectCommand = myComm;
        da.Fill(ds, "Products");

        // Retrieving the total count of rows
        OleDbConnection myConn2 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Web.HttpContext.Current.Server.MapPath("../App_Data/Northwind.mdb"));
        OleDbCommand    myComm2 = new OleDbCommand("SELECT COUNT(*) FROM Products", myConn2);

        myConn2.Open();
        int count = (int)(myComm2.ExecuteScalar());

        myConn2.Close();

        // Passing the total count to the "TotalRowCount" property of the GridDataSourceNeededEventArgs object
        e.TotalRowCount = count;

        // Populating the grid
        grid1.DataSource = ds.Tables[0];
        grid1.DataBind();
    }
    protected void Grid1_DataSourceNeeded(object sender, GridDataSourceNeededEventArgs e)
    {
        // Preparing the SQL query for populating the Grid
        string sortExpression = "";

        if (string.IsNullOrEmpty(e.SortExpression))
        {
            sortExpression = " ORDER BY ProductID DESC";
        }
        else
        {
            sortExpression = " ORDER BY " + e.SortExpression;
        }

        string query = "SELECT TOP " + e.MaximumRows.ToString() + " * FROM (SELECT ProductID, CategoryID, ProductName, UnitPrice FROM Products";
        if (e.StartRowIndex != 0)
        {
            query += " WHERE ProductID NOT IN (SELECT TOP " + e.StartRowIndex.ToString() + " ProductID FROM Products" + sortExpression + ")";
        }
        query += sortExpression;
        query += ")";

        // Extracting the rows
        OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../App_Data/Northwind.mdb"));
        OleDbCommand myComm = new OleDbCommand(query, myConn);
        myConn.Open();
        OleDbDataAdapter da = new OleDbDataAdapter();
        DataSet ds = new DataSet();
        da.SelectCommand = myComm;
        da.Fill(ds, "Products");

        // Retrieving the total count of rows
        OleDbConnection myConn2 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Web.HttpContext.Current.Server.MapPath("../App_Data/Northwind.mdb"));
        OleDbCommand myComm2 = new OleDbCommand("SELECT COUNT(*) FROM Products", myConn2);
        myConn2.Open();
        int count = (int)(myComm2.ExecuteScalar());

        myConn2.Close();

        // Passing the total count to the "TotalRowCount" property of the GridDataSourceNeededEventArgs object
        e.TotalRowCount = count;

        // Populating the grid
        Grid1.DataSource = ds.Tables[0];
        Grid1.DataBind();
    }
    protected void Grid1_DataSourceNeeded(object sender, GridDataSourceNeededEventArgs e)
    {
        level++;

        e.HandledFiltering = false;
        e.HandledPaging = false;
        e.HandledSorting = false;

        Grid grid = (Grid)sender;

        AddDetailGrid(grid);

        if (!(grid is DetailGrid))
        {
            PopulateGrid(grid, "");
        }
        else
        {
            PopulateGrid(grid, e.ForeignKeysValues["CategoryID"]);
        }
    }
Пример #4
0
    protected void Grid1_DataSourceNeeded(object sender, GridDataSourceNeededEventArgs e)
    {
        level++;

        e.HandledFiltering = false;
        e.HandledPaging    = false;
        e.HandledSorting   = false;

        Grid grid = (Grid)sender;

        AddDetailGrid(grid);

        if (!(grid is DetailGrid))
        {
            PopulateGrid(grid, "");
        }
        else
        {
            PopulateGrid(grid, e.ForeignKeysValues["CategoryID"]);
        }
    }
    protected void Grid1_DataSourceNeeded(object sender, GridDataSourceNeededEventArgs e)
    {
        // Preparing the SQL query for populating the Grid
        string sortExpression = "";
        string filterExpression = "";

        if (string.IsNullOrEmpty(e.SortExpression))
        {
            sortExpression = " ORDER BY OrderID DESC";
        }
        else
        {
            sortExpression = " ORDER BY " + e.SortExpression;
        }

        if (!string.IsNullOrEmpty(e.FilterExpression))
        {
            filterExpression = e.FilterExpression;
        }

        string query = "SELECT TOP " + e.MaximumRows.ToString() + " * FROM (SELECT OrderID, ShipName, ShipCity, ShipAddress, ShipPostalCode, ShipCountry FROM Orders";
        if (e.StartRowIndex != 0)
        {
            query += " WHERE OrderID NOT IN (SELECT TOP " + e.StartRowIndex.ToString() + " OrderID FROM Orders";
            query += (string.IsNullOrEmpty(filterExpression) ? "" : " WHERE " + filterExpression) + sortExpression + ")";
            if (!string.IsNullOrEmpty(filterExpression))
            {
                query += " AND " + filterExpression;
            }
        }
        else
        {
            if (!string.IsNullOrEmpty(filterExpression))
            {
                query += " WHERE " + filterExpression;
            }
        }
        query += sortExpression + ")";

        // Extracting the rows
        OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../App_Data/Northwind.mdb"));
        OleDbCommand myComm = new OleDbCommand(query, myConn);
        myConn.Open();
        OleDbDataAdapter da = new OleDbDataAdapter();
        DataSet ds = new DataSet();
        da.SelectCommand = myComm;
        da.Fill(ds, "Orders");


        string countQuery = "SELECT COUNT(*) FROM Orders";
        if (!string.IsNullOrEmpty(filterExpression))
        {
            countQuery += " WHERE " + filterExpression;
        }

        // Retrieving the total count of rows
        OleDbConnection myConn2 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Web.HttpContext.Current.Server.MapPath("../App_Data/Northwind.mdb"));
        OleDbCommand myComm2 = new OleDbCommand(countQuery, myConn2);
        myConn2.Open();
        int count = (int)(myComm2.ExecuteScalar());

        myConn2.Close();

        // Passing the total count to the "TotalRowCount" property of the GridDataSourceNeededEventArgs object
        e.TotalRowCount = count;

        // Populating the grid
        grid1.DataSource = ds.Tables[0];
        grid1.DataBind();
    }
Пример #6
0
    protected void Grid1_DataSourceNeeded(object sender, GridDataSourceNeededEventArgs e)
    {
        // Preparing the SQL query for populating the Grid
        string sortExpression   = "";
        string filterExpression = "";

        if (string.IsNullOrEmpty(e.SortExpression))
        {
            sortExpression = " ORDER BY OrderID DESC";
        }
        else
        {
            sortExpression = " ORDER BY " + e.SortExpression;
        }

        if (!string.IsNullOrEmpty(e.FilterExpression))
        {
            filterExpression = e.FilterExpression;
        }

        string query = "SELECT TOP " + e.MaximumRows.ToString() + " * FROM (SELECT OrderID, ShipName, ShipCity, ShipAddress, ShipPostalCode, ShipCountry FROM Orders";

        if (e.StartRowIndex != 0)
        {
            query += " WHERE OrderID NOT IN (SELECT TOP " + e.StartRowIndex.ToString() + " OrderID FROM Orders";
            query += (string.IsNullOrEmpty(filterExpression) ? "" : " WHERE " + filterExpression) + sortExpression + ")";
            if (!string.IsNullOrEmpty(filterExpression))
            {
                query += " AND " + filterExpression;
            }
        }
        else
        {
            if (!string.IsNullOrEmpty(filterExpression))
            {
                query += " WHERE " + filterExpression;
            }
        }
        query += sortExpression + ")";

        // Extracting the rows
        OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../App_Data/Northwind.mdb"));
        OleDbCommand    myComm = new OleDbCommand(query, myConn);

        myConn.Open();
        OleDbDataAdapter da = new OleDbDataAdapter();
        DataSet          ds = new DataSet();

        da.SelectCommand = myComm;
        da.Fill(ds, "Orders");


        string countQuery = "SELECT COUNT(*) FROM Orders";

        if (!string.IsNullOrEmpty(filterExpression))
        {
            countQuery += " WHERE " + filterExpression;
        }

        // Retrieving the total count of rows
        OleDbConnection myConn2 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Web.HttpContext.Current.Server.MapPath("../App_Data/Northwind.mdb"));
        OleDbCommand    myComm2 = new OleDbCommand(countQuery, myConn2);

        myConn2.Open();
        int count = (int)(myComm2.ExecuteScalar());

        myConn2.Close();

        // Passing the total count to the "TotalRowCount" property of the GridDataSourceNeededEventArgs object
        e.TotalRowCount = count;

        // Populating the grid
        grid1.DataSource = ds.Tables[0];
        grid1.DataBind();
    }