在代码中设置gridview数据源时未生成列 [英] Columns not being generated when gridview datasource is set in code

查看:65
本文介绍了在代码中设置gridview数据源时未生成列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true">
</asp:GridView>







GridView1.AutoGenerateColumns = true;
GridView1.DataSource = db.Snippets.ToList();
GridView1.DataBind();
//shows us that we have no columns
giveJavascriptMessage(GridView1.Columns.Count.ToString());

//I want to be able to hide specific columns at the moment this returns an index out              of range
GridView1.Columns[0].visible=false;





我使用实体框架模型来填充gridview。



当我运行此代码时,它会创建网格视图并使用表填充它,但是当我尝试访问网格视图中的列时,没有giveJavascriptMessage(GridView1.Columns.Count.ToString());

返回0



为什么没有列被创建,尽管所有数据都显示在页面上?

如何创建列?



Im using an entity framework model to populate the gridview.

When I run this code it creates the grid-view and populates it with the table but when I try to access the columns in the grid view there are none "giveJavascriptMessage(GridView1.Columns.Count.ToString());"
returns 0

Why are no columns being created although all data is shown on the page?
How can I get the columns to be created?

推荐答案

您好,

尝试此解决方案,

< a href =http://stackoverflow.com/questions/2091457/how-to-hide-columns-in-an-asp-net-gridview-with-auto-generated-columns> http://stackoverflow.com / questions / 2091457 / how-to-hide-in-an-asp-net-gridview-with-auto-generated-columns [ ^ ]



希望它可以帮到你。

谢谢。
Hi,
Try this solution,
http://stackoverflow.com/questions/2091457/how-to-hide-columns-in-an-asp-net-gridview-with-auto-generated-columns[^]

Hope it helps you.
Thanks.


这篇关于在代码中设置gridview数据源时未生成列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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