开发者

Show Header and Footer on empty GridView using Linq to Sql

I have a gridview that I am using for data entry.

The logic behind it is that the user enters data row by row from a shopping receipt. The query returns all items logged on that day, so when the first item is entered there will be no rows returned from the query:

var qPurchase = from p in db.purchases
                        where p.purchaseDate.Date == DateTime.Now.Date
                        select new
                        {
                            p.purchaseID,
                            p.product.name,
                            p.product.units,
                            p.product.priceMarked,
                            p.packCost,
                            p.product.vat,
                            p.unitSalePrice,
                            p.bestBefore 
                        开发者_StackOverflow};

            gvPurchases.DataSource = qPurchase;
            gvPurchases.DataBind();

How can I show the footer when there is no data returned? Have looked around and there are a few examples when using a datatable, but nothing Linq based.

Any help much appreciated.


I think you can set the EmptyDatatext value for the grid view and that will make the footer appear.

However I think what you might want to consider is if there is no data in the grid view then qPurchase should bind to a row that is empty. So if it comes back with no results then add a result to it that has 0s or empty strings and then prompt the user to fill that in. You can either do this by setting a value in qPurchase like you have or by making a row and adding it to the grid view in the case there is no results.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜