让GridView的页脚可见,当没有数据绑定 [英] Make GridView footer visible when there is no data bound

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

问题描述

如何显示页脚当在GridView中没有数据从页脚插入数据。

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

推荐答案

要做到这一点最简单的方法是将数组绑定一个的长度。你可以把它你想确定,这是一个虚设行任何东西。在您的GridView的的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天全站免登陆