显示没有数据的GridView [英] display gridview with out data

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

问题描述

你好先生.
我采取了一个gridview.有两列,如下所示.我想在每次加载页面时显示这两列.即使我拿了一个标签也没有显示.
我想在每次打开空白页面时显示此gridview.要执行此任务,我该怎么办.如果有人知道请帮助我.
谢谢.

卫星.



hello sir.
i took one gridview. with two columns like below. i want to display these two columns when ever i load the page. even i took one label also it is not displaying.
i want to display this gridview when ever i open the page empty. to do this task what can i do. if any body know plz help me.
thanking you.

sateesh.



<asp:GridView ID="GV" runat="server" AutoGenerateColumns ="false" >
            <Columns>
                <asp:TemplateField Visible="true" HeaderText ="ID">
                    <ItemTemplate>
                        <asp:Label ID="id" runat="server" Text="<%#Eval("123")%>"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText ="Name" Visible ="true" >
                    <ItemTemplate >
                        <asp:Label ID="Name" runat="server" Text="<%#Eval("123")%>"> </asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

推荐答案

可以.

如果您注意到如何填充GridView的代码,您会发现您获得了一个数据集/数据表并将其作为数据源分配给网格.之后,调用它的Databind方法.

在内部,数据是绑定的,并且Rowdatabound的调用次数是数据表中返回的行数的多少倍.作为回报,这些行将显示给您.

现在,在您的页面加载或任何给定的情况下,如果分配给网格的数据表中包含零行,则将没有绑定,因此将不会显示网格或标题等.

为了处理这种情况,以便您仍然可以看到网格标题或其中的某些标签,您需要从侧面编写一些额外的代码.步骤:
1.在将数据源分配给网格之前,请检查表中的行数
2.如果大于零,则继续正常流量
3.如果它为零,则从您的侧面创建一个虚拟表,添加一个没有任何值或一些文本的虚拟行
4.将此新表分配给grid并调用databind方法.

完毕!试试.
Sure.

If you notice the code of how GridView is populated, you will find that you get a dataset/datatable and assign that as a datasource to grid. After which you call a Databind method of it.

Internally, data is binded and Rowdatabound is called that many number of times as much number of rows returned in the datatable. This in return shows you those rows.

Now, at your page load or any given scenario, if the datatable assigned to the grid is having ZERO rows in it then there would be no binding and thus no display of grid or headers etc.

In order to handle this scenario such that you still see headers of grid or some label in it, you need to write a little extra code from your side. Steps:
1. Before assigning the datasource to grid, check for number of rows in the table
2. If it''s more than zero then go with normal flow
3. If it''s zero then create a dummy table from your side, add a dummy row with no values or some text in it
4. Assign this new table to grid and call databind method.

Done! Try.


这篇关于显示没有数据的GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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