本文介绍了如何在gridview的数据源为空时显示页脚行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gridview,我使用list进行数据绑定,我没有使用数据集或数据表或任何其他sqldatasource。我试过ShowFooter =true,我还有一个页脚,设计允许用户在gridview没有行时输入数据。即使我尝试使用空值初始化我的列表类,但它显示的行包含已分配默认值的列它看起来很糟糕。(有时null rerefence异常..)。因此,当使用列表作为gridview的数据源时,我想要一个干净的解决方案来显示没有数据集或数据表的页脚...谢谢所有...

i have a gridview and i do data binding using list and i am not using dataset or datatable or any other sqldatasource. i tried ShowFooter="true" and i also have a footer designed to allow users to enter data when gridview has no rows..Even i tried initialising my list class with null values but it shows a row with columns that has default values assigned to it that looks bad.(sometimes null rerefence exception..). So i want a clean solution to show footer without dataset or datatable when using list as datasource of gridview... Thanks all...

推荐答案



if(list.Count>0)//check if list empty
{}
else
{
Classname obj=new Classname();//initialize empty class that may contain properties
list.Add(obj);//Add empty object to list
grid1.DataSource=list;/*Assign datasource to create one row with default values for the class you have*/
grid1.DataBind();//Bind that empty source
grid1.Rows[0].Visible=false//Make that row's visibility false
}


这篇关于如何在gridview的数据源为空时显示页脚行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 19:48
查看更多