开发者

C#: How do I check if a DataGrid is empty?

开发者 https://www.devze.com 2022-12-13 14:35 出处:网络
I have a DataGrid which I want to check开发者_JS百科 whether empty or not. Is there a way to do this? Currently, I have an idea like below code.

I have a DataGrid which I want to check开发者_JS百科 whether empty or not. Is there a way to do this? Currently, I have an idea like below code.

if (grdMass.DataSource=="")
{
    cmdRelease.Enabled = false;
}
else
{
    cmdRelease.Enabled = true; ;
}

Can someone help me please? Thank you.


To check if something is empty you can check if the Items property is empty.

grdMass.Items.Count == 0


The only way to check if the grid view is empty is by checking the number of rows it has.

if(gvMyData.Rows.Count == 0)
     // Empty
else
     // Not Empty

Hope this helps ;)


If nothing has been bound to the DataGrid the DataSource property will be null:

cmdRelease.Enabled = (grdMass.DataSource != null);
0

精彩评论

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

关注公众号