Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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<OrganizationType> ListAllOrganizationType = obj_OrganizationType.SelectAll();
string OrganizationNameSearch = cmb_OrganizationTypeName.Text.ToString().ToLower();
var ListOrganzaitionType = (List<OrganizationType>)(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<OrganizationType>(ListOrganzaitionType);
}
else
{
MessageBox.Show("No Records Found", "Alert");
}
}

Kindly let me know what is the error in the above code.

Thank you.
Posted

1 solution

Hello ,
Check whether it contains any element or not by this way .
if (ListOrganzaitionType!=null)
{
//bidn grid
}
else 
{
//alert message
}

thanks
Animesh
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900