简体   繁体   中英

how to handle empty itemsource in datagrid

I have a datagrid in my program, where data is coming from a SQL stored procedure and columns names are autogenerated. Below is my xaml definition for datagrid.

When my page is loaded, stored procedure is executed and data is populated into this grid with headers.

For case where results are empty, I would like to show the header names and wanted to show a message to the user.

<DataGrid Name="datagrid"
    Margin="12,77,52,156"
    DataContext="{Binding}"
    IsReadOnly="True" 
    Grid.RowSpan="2"
    Grid.ColumnSpan="2" 
    AlternatingRowBackground="#FFF2F2F2"
    AreRowDetailsFrozen="True"
    CanUserResizeRows="False"
    ClipboardCopyMode="IncludeHeader"
    Focusable="False"
    MinRowHeight="1">
</DataGrid>

After binding data to the data grid, you can check the record count and display a message in case the record count is 0. Hope the example in this page helps.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM