views:

38

answers:

1

Hi guys,

Can someone please assist me. I have dynamically created controls onto my page which consists of a GridView, DropDownList, TextBox and Button.

I have successfully retrieved data onto the GridView control which then has a paging attribute enabled. Now I am trying to filter data according to the input set by the user through the DropDownList and the TextBox fired by the Button click event. However, it doesn't work.

I have the following code:

In CreateChildControls:

Controls.Add(_searchTitle);
Controls.Add(_searchDDL);
Controls.Add(_searchTextBox);
Controls.Add(_searchBtn);
Controls.Add(new LiteralControl("<br /><br />"));

Controls.Add(_title);
Controls.Add(new LiteralControl("<br /><br />"));

SelectEmployees(_searchDDL, _searchTextBox, _grid, _empObj, _dt, _strConn);
EmployeesGrid(_grid, _IDColumn, _hyperlinkedColumn, _column, _title);
Controls.Add(_grid);
DesignGrid(_grid);

if(!Page.IsPostBack)
{
   SearchArea(_searchTitle, _searchDDL, _searchTextBox, _searchBtn);
}

SelectEmployees method is responsible for querying the data. EmployeesGrid only renders the query onto the GridView control. DesignGrid is the method that defines the style for the grid. SearchArea defines the style for the search controls.

The following code is called upon button click. However, it doesn't do anything:

private void FilterEmployees(DropDownList searchDDL, TextBox searchTextBox, GridView grid, DataTable dt)
{
   string col = "";

   if ((searchDDL.SelectedValue.Equals("First Name")) && (!searchTextBox.Text.Equals("")))
   {
      col = "FirstName = " + searchTextBox.Text;
   }
   else if ((searchDDL.SelectedValue.Equals("Last Name")) && (!searchTextBox.Text.Equals("")))
   {
      col = "LastName" + searchTextBox.Text;
   }
   else if ((searchDDL.SelectedValue.Equals("Department")) && (!searchTextBox.Text.Equals("")))
   {
      col = "Department" + searchTextBox.Text;
   }
   else if ((searchDDL.SelectedValue.Equals("ID Number")) && (!searchTextBox.Text.Equals("")))
   {
      col = "IDNumber" + searchTextBox.Text;
   }
   else
   {

   }

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

   DesignGrid(grid);


}

Please help. Thanks.

A: 

Hi.. Sorry. I could be very silly here. Could it be because there is no call to the "grid.DataBind()" method?

I just tried a very similar program and I was able to filter as you expect.

-Prasanna K Rao

Prasanna K Rao
Hi, I have a DataBind method inside the DesignGrid...
janejanejane