填充上运行一个gridview [英] Populate a gridview on runtime
问题描述
我有,我想,以填补在一些通用的列表中的数据一个gridview。
我用了一个数据表作为数据源里面有我需要的列(DataColumn的)。
I have a gridview that I want to fill with data in some generic lists. I used a "DataTable" as DataSource which has the columns I need (DataColumn).
GridView1.DataSource = CreateDataTable();
我的问题是我的GridView控件包含HTML标记,所以我需要这样的东西。
My problem is my gridview contains html tags so I need something like
myBoundedField.HtmlEncode = false;
和我需要更改列的标题而这一切是不可能的,如果我使用的DataColumn。我发现了一些code谈论的BoundField。
为什么/当我应该用绑定列呢?哪些好处?
and I need to change the caption of the columns and all this is not possible if I use "DataColumn". I found some code talking about BoundField. why/when should I use BoundField instead? what are the benefit?
推荐答案
创建您 GridView的列
对象并将其添加到 GridView的Columns集合
。你可以创建自己的的ItemTemplate
只是像你想操纵你的cuustom值的列 HTML
在这里。
Create you GridView Column
Objects and add them to Gridview's Columns collection
. and you can create your own ItemTemplates
for columns for your cuustom values just like you want to manipulate HTML
here.
GridView gvDynamicArticle = new GridView();
gvDynamicArticle.Width = Unit.Pixel(700);
gvDynamicArticle.BorderWidth = Unit.Pixel(0);
gvDynamicArticle.Caption = "Report View";
gvDynamicArticle.AutoGenerateColumns = false;
gvDynamicArticle.ShowFooter = true;
TemplateField tf = null;
tf = new TemplateField();
tf.HeaderTemplate = new DynamicGridViewTextTemplate("ArticleID", DataControlRowType.Header);
tf.ItemTemplate = new DynamicGridViewTextTemplate("ArticleID", DataControlRowType.DataRow);
tf.FooterTemplate = new DynamicGridViewTextTemplate(DataControlRowType.Footer, ds.Tables[i].Rows.Count);
gvDynamicArticle.Columns.Add(tf);
按照以下链接了解更多信息:
follow these link for more information:
<一个href=\"http://www.$c$cdigest.com/Articles/ASPNET/168_Create_Dynamic_GridView_Control_in_C_ASPNet.aspx\" rel=\"nofollow\">http://www.$c$cdigest.com/Articles/ASPNET/168_Create_Dynamic_GridView_Control_in_C_ASPNet.aspx
HTTP://www.$c$cproject.com/KB/ ASPNET / dynamic_Columns_in_Grid.aspx
<一个href=\"http://www.dotnetfunda.com/articles/article1400-how-to-generate-gridview-columns-dynamically-based-on-user-selection.aspx\" rel=\"nofollow\">http://www.dotnetfunda.com/articles/article1400-how-to-generate-gridview-columns-dynamically-based-on-user-selection.aspx
添加一些列有界,你可以访问在 rowcreated
事件数据,然后使用 server.htmlDeocde(小于HTML EN codeD场值&GT;)
在网格中显示..以同样的方式,你可以(节约行命令的html code与 HtmlEn code LT;保存HTML场值方式&gt;)
使用此事件
Add some bounded column and you can access data at rowcreated
event and then use server.htmlDeocde( <html encoded field value>)
to show in the grid.. in the same way you can save html code on row command with HtmlEncode( <save html field value> )
using this event.
希望这有助于你..
这篇关于填充上运行一个gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!