views:

8

answers:

0

Hello,

How can I enable the paging feature of a gridview that has been filtered using a dataview source. The paging on the default view is working fine. However, when the user inputs a value to be used in filtering the data, the paging reverts back to the original datasource even after the databind has been called. The following code accesses the database:

private void SelectEmployees(DropDownList searchDDL, TextBox searchTextBox, GridView grid, EmployeesListAccess empObj, DataTable dt, string strConn)
{
        string col = "";
        string query = "";

        if ((searchDDL.SelectedValue.ToString().Equals("First Name")) && (!searchTextBox.Text.Equals("")))
        {
            query = "SELECT EMP_ID, firstname, lastname, idnumber, department FROM EMPLOYEES WHERE firstname LIKE '%" + searchTextBox.Text + "%' AND STATUS='R' AND DEPARTMENT NOT IN ('RESIGNED','REDUNDANT');";
            col = "firstname = '" + searchTextBox.Text.ToString() + "'";
        }
        else if ((searchDDL.SelectedValue.Equals("Last Name")) && (!searchTextBox.Text.Equals("")))
        {
            query = "SELECT EMP_ID, firstname, lastname, idnumber, department FROM EMPLOYEES WHERE lastname LIKE '%" + searchTextBox.Text + "%' AND STATUS='R' AND DEPARTMENT NOT IN ('RESIGNED','REDUNDANT');";
            col = "lastname = '" + searchTextBox.Text.ToString() + "'";
        }
        else if ((searchDDL.SelectedValue.Equals("Department")) && (!searchTextBox.Text.Equals("")))
        {
            query = "SELECT EMP_ID, firstname, lastname, idnumber, department FROM EMPLOYEES WHERE department LIKE '%" + searchTextBox.Text + "%' AND STATUS='R' AND DEPARTMENT NOT IN ('RESIGNED','REDUNDANT');";
            col = "department LIKE '%" + searchTextBox.Text.ToString() + "%'";
        }
        else if ((searchDDL.SelectedValue.Equals("ID Number")) && (!searchTextBox.Text.Equals("")))
        {
            query = "SELECT EMP_ID, firstname, lastname, idnumber, department FROM EMPLOYEES WHERE idnumber = '" + searchTextBox.Text + "' AND STATUS='R' AND DEPARTMENT NOT IN ('RESIGNED','REDUNDANT');";
            col = "idnumber = '" + searchTextBox.Text.ToString() + "'";
        }
        else
        {
            query = "SELECT EMP_ID, firstname, lastname, idnumber, department FROM EMPLOYEES WHERE STATUS='R' AND DEPARTMENT NOT IN ('RESIGNED','REDUNDANT');";
        }

        empObj.StrConn = strConn;
        dt = empObj.SQLResult(query);

        _view = new DataView(dt);
        _view.RowFilter = col;
        grid.DataSource = _view;
    }

protected void grid_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        _grid.PageIndex = e.NewPageIndex;
        _grid.DataSource = _view;
        _grid.DataBind();
    }