让GridView的页脚可见,当没有数据绑定绑定、数据、GridView

2023-09-04 12:41:38 作者:灵笛等君归

如何显示页脚当在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;
        }
    }
}