使用数据表如何逐行添加列名 [英] using datatable how to add column name maually

查看:131
本文介绍了使用数据表如何逐行添加列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用数据表如何手动添加列名.


我有如下的gridview

我想使用gridview中的数据表手动添加以下三个名称


课程
批处理
评分


在Gridview中,我希望输出如下所示


课程批处理率

using datatable how to add column name manually.


I have gridview as follows

i want to add the following three names manually using datatable in gridview


Course
Batchid
Rate


in Gridview i want the output as follows


Course Batchid Rate

推荐答案

您可以使用DataTable列.添加

参考:
C#数据表 [ ^ ]



添加了链接文字以反映文章标题.
更正了格式问题.
[/Edit]
You can use DataTable Columns. Add

Reference:
C# DataTable[^]



Link text added to reflect the article title.
Corrected formatting issues.
[/Edit]


尝试一下.希望它适合您.

Try This. Hope it suits you.

<asp:gridview id="GridView1" runat="server" autogeneratecolumns="false" onrowdatabound="GridView1_RowDataBound" xmlns:asp="#unknown">
     <columns>
          <asp:templatefield headertext="Course">
               <itemtemplate>
               DO Something!
               </itemtemplate>
          </asp:templatefield>
     </columns>
     <columns>
          <asp:templatefield headertext="Batchid">
               <itemtemplate>
               DO Something!
               </itemtemplate>
          </asp:templatefield>
     </columns>
     <columns>
          <asp:templatefield headertext="Rate">
               <itemtemplate>
               DO Something!
               </itemtemplate>
          </asp:templatefield>
     </columns>
</asp:gridview>


请参见参考代码.
See the reference code.
DataTable Dt = new DataTable();
DataColumn Dc = new DataColumn("Course");
DataColumn Dc1 = new DataColumn("Batchid");
DataColumn Dc2 = new DataColumn("Rate");
Dt.Columns.Add(Dc);
Dt.Columns.Add(Dc1);
Dt.Columns.Add(Dc2);

DataRow dr = Dt.NewRow();
dr["Course"] = "MCA";
dr["Batchid"] = "111";
dr["Rate"] = "A";
Dt.AcceptChanges();


这篇关于使用数据表如何逐行添加列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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