GST Billing Software

header image

Preferred Settings in Dialog Box

Erachana Line

34. How to apply filter to a Dropdown, Listbox, Datagrid?

In Kushal, we have a default function called ControlAdapter.Filter which will help us to get the filtered data to a control using certain conditions. This is applicable for dropdown, listbox and datagrid. For Dropdown and list box, use the following syntax.

Syntax – ControlAdapter.Filter(Listbox Name/Dropdown Name, Condition, Field SQLs)


ControlAdapter.Filter(txt_PlaceId, "StateId=" + txt_State.SelectedValue, fieldSqls);

ControlAdapter.Filter(lst_billType, "billTypeId=2”, fieldSqls);

For Datagrid:

Syntax – ControlAdapter.Filter(Grid Name, Condition)

ControlAdapter.Filter(dgrData, "PartyTypeId=1”);

Note: To do filters, please check the datasource of the control, datasource is not null, and conditions are proper etc. to avoid runtime exceptions.

Example –

if (txt_PlaceId.DataSource != null && txt_State.DataSource != null && txt_State.SelectedIndex >= 0)


ControlAdapter.Filter(txt_PlaceId, "StateId=" + txt_State.SelectedValue, fieldSqls);

txt_PlaceId.SelectedIndex = -1;



if (FilterValue Condition)


ControlAdapter.Filter(Grid_Id/Listbox_Id/Dropdown_Id, string.Format("Column _Name LIKE ('%{0}%')", FilterValue));




ControlAdapter.Filter(Grid_Id/Listbox_Id/Dropdown_Id, "");