没有数据绑定时使 GridView 页脚可见 [英] Make GridView footer visible when there is no data bound

查看:23
本文介绍了没有数据绑定时使 GridView 页脚可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在gridview中没有数据用于从页脚插入数据时显示页脚.

how to show footer when there is no data in gridview for inserting data from footer.

推荐答案

最简单的方法是绑定一个长度为 1 的数组.您可以在其中放入任何您喜欢的内容来确定这是一个虚拟行.在您的 GridViews RowDataBound 方法中,检查数据项是否为虚拟行(在尝试检查数据之前首先确保 RowType 是 DataRow).如果它是虚拟行,则将行可见性设置为 false.页脚和页眉现在应该没有任何数据显示.

The easiest way to do this is to bind an array with a length of one. You can put anything in it you like to identify that this is a dummy row. On your GridViews RowDataBound method check to see if the data item is the dummy row (make sure the RowType is a DataRow first before trying to check the data). If it is the dummy row set the rows visibility to false. The footer and header should now be showing without any data.

确保在 GridView 上将 ShowFooter 属性设置为 true.

Make sure you set the ShowFooter property to true on your GridView.

例如

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostback)
    {
         myGrid.DataSource = new object[] {null};
         myGrid.DataBind();
    }
}    

protected void myGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if (e.Row.DataItem == null)
        {
             e.Row.Visible = false;
        }
    }
}

这篇关于没有数据绑定时使 GridView 页脚可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆