Search code examples
asp.net-mvc-3webgrid

Custom message inside the webgrid if empty


  @if (Model.ActivityCollection.Count > 0)
        {
        var grid = new WebGrid(source: Model.ActivityCollection, rowsPerPage: 12, canSort: false);   
            @grid.GetHtml(tableStyle: "webGrid",
            headerStyle: "header",
            alternatingRowStyle: "alt",
            columns: grid.Columns(
            grid.Column("EffectiveDate", "Effective Date", style: "date"),
            grid.Column("PremiumPaymentAmount", "Premium Payment Amount", style: "amount"),
            grid.Column("PaymentType", "Payment Type", style: "date")
           ));
        }
else
        {

        }

I would like to display a message "No Payment Information Found" inside the web grid in the above else statement. Can someone help me with this?


Solution

  • <div class="grid" style="margin-left:5px;" id="grid">          
            @if (Model.ActivityCollection.Count > 0)
            {
                var grid = new WebGrid(source: Model.ActivityCollection, rowsPerPage: 12, canSort: false);   
                @grid.GetHtml(tableStyle: "webGrid",
                headerStyle: "header",
                alternatingRowStyle: "alt",
                columns: grid.Columns(
                grid.Column("EffectiveDate", "Effective Date", style: "date"),
                grid.Column("PremiumPaymentAmount", "Premium Payment Amount", style: "amount"),
                grid.Column("PaymentType", "Payment Type", style: "date")
               ));
            }
            else
            {
                <div class="grid">
                <table cellspacing="0" width="80%">
                   <thead>
                        <tr>
                            <th>Effective Date</th>
                            <th>Premium Payment Amount</th>
                            <th>Payment Type</th>
                            </tr>
                    </thead>
                    <tbody>
                     <tr>
                            <td colspan="3" align="center" ><br />No payment information found<br /><br /> </td>
                     </tr>                     
                    </tbody>
                </table>
                <br/><br/><br/><br/>
                </div>
            }
            </div>