Hi,
I am creating a Windows Application. I am unable to Bind DataGridView. I am using the following code to bind DataGrid. The code does not show any error but every time I try to bind DataGrid, it does not display any value.
private void BindGridView()
{
List ListAllOrganizationType = obj_OrganizationType.SelectAll();
string OrganizationNameSearch = cmb_OrganizationTypeName.Text.ToString().ToLower();
var ListOrganzaitionType = (List)(from OrgType in ListAllOrganizationType where (OrganizationNameSearch == string.Empty ? true : (OrgType.TypeName.ToLower().Contains(OrganizationNameSearch))) select OrgType).ToList();
if (ListOrganzaitionType.Count > 0)
{
gv_OrganizationType.DataSource = new List(ListOrganzaitionType);
}
else
{
MessageBox.Show("No Records Found", "Alert");
}
}
Kindly let me know what is the error in the above code.
Thank you.
Khargesh RajputPosted Jan 27, 2015, 4:35 AM
to filter datagrid
like in below link
http://www.c-sharpcorner.com/UploadFile/1a81c5/filter-datagridview-with-the-text-entered-in-textbox-in-winf/
Harsh JaniPosted Jan 27, 2015, 4:29 AM
Actually, I want to implement a simple search functionality. In this case, ListAllOrganizationType fetches the list of all Organization types. From this list, I want to filter out the Organization Type which matches the string OrganizationNameSearch. Hence, I have fired a query which filters out the OrganizationType and stores it in var ListOrganizationType.
I want to bind this filtered list to DataGrid. And therefore, I have used ListOrganizationType as Data source.
Khargesh RajputPosted Jan 27, 2015, 4:11 AM
your datasource sholud be ListAllOrganizationType
Harsh JaniPosted Jan 27, 2015, 3:41 AM
This is a windows application. So, I cannot use DataBind() method.
Khargesh RajputPosted Jan 27, 2015, 1:27 AM
gv_OrganizationType.Databind();