如何通过GridView绑定数据源的列的一部分? [英] How to bind one part of columns of a DataSource by GridView?

查看:88
本文介绍了如何通过GridView绑定数据源的列的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不希望将数据源的所有列绑定到GridView上,而是将其中的一部分绑定到GridView上,但是我不知道可以使用哪个函数?

I want to bind not all but one part of columns of a DataSource to a GridView, but I do not know which function can be used?

例如,以下代码用于将数据库"Departments"的所有列绑定到GridView departmentsGrid.

For example, the following code is used to bind all columns of database "Departments" to GridView departmentsGrid.

departmentsGrid.DataSource = dataSet.Tables["Departments"].DefaultView;
departmentsGrid.DataBind();

请注意,对于GridView,我已将"AutoGenerateColumns"设置为True.

Note that for the GridView, I have set "AutoGenerateColumns" as True.

因此,我必须选择所有要绑定的列.也许,我可以将"AutoGenerateColumns"设置为False,然后一一绑定列?

Therefore, I have to select all the columns to bind. Perhaps, I can set "AutoGenerateColumns" as False and then bind the columns one by one?

还是有更好的解决方案?

Or is there any better solution?

谢谢!

推荐答案

您必须在Gridview的RowDataBound事件上进行此操作.
You have to do it on RowDataBound Event of Gridview.


总是最好在设计器上指定列,而AutoGenerateColumns设置为false.这样,如果对部门的选择发生更改,页面将保持不变.

[竖起大拇指]

It is always better to specify columns on the designer and AutoGenerateColumns false. So that if the selection to departments changes the page becomes intact.

[thumbs up]


这篇关于如何通过GridView绑定数据源的列的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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