开发者

GridView with paging enabled is not filtering based on input from other Controls (DropDownList, TextBox)

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(_se开发者_运维百科archTitle);
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.


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


Are you sure that you are re-adding your controls on postback with the correct selected values? (you need to add your controls to session and load them everytime on postback)

If you are doing so, can you show us where you bind the onclick event to your button.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜