在gridview中动态创建行和列 [英] dynamically created row and column in gridview

查看:72
本文介绍了在gridview中动态创建行和列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



我想动态创建行和列到gridview。

eg;



列基于本月的日期,创建的行基于主要人物的儿童。





如果我有孩子2,那么gridview包含2行,列包含28(因为2月份)





一般我想为Main的Sub员工注册。



所以,如果有任何其他解决方案,请帮助我或指导我Gridview在C#。



提前致谢....

Mitesh

解决方案

< blockquote>问题是什么?



对于基于月份的列:

步骤:

1.获取当前月份

2.根据当前月份的最后一天数字,您可以运行循环并将这些列添加到网格/表格

3.基于子项PE rson,你会有那么多行。根据你所说的,它听起来像是空的一整天。



结合并且你有很多列和行的网格。现在,试试吧。我相信会有更多这方面的内容。添加其他详细信息,如果您遇到问题,请发布特定问题。


您好,



创建数据表对象和列声明然后最终将该列添加到Row。



DataTable dtable = new DataTable();

 dtable.Columns。添加( new  DataColumn(  Day1 typeof  string ))); 
dtable.Columns.Add( new DataColumn( Day2 typeof string )));
dtable.Columns.Add( new DataColumn( Day3 typeof string )));
dtable.Columns.Add( new DataColumn( Day4 typeof string )));
dtable.Columns.Add( new DataColumn( Day5 typeof string ))); ..... 28
DataRow dr = dtable.NewRow();
dr [ 0 ] = Datareader.GetValue( 0 )。ToString();
dr [ 1 ] = Datareader.GetValue( 1 )。ToString(); - 。 .......... 28
dtable.Rows.Add(dr);


Dear All,

I want to create dynamically row and column in to the gridview.
e.g ;

column is based on the days of this month and row created is based on child person for the main person.


if i have child person 2 then gridview contains 2 row and column contains 28 ( because of the Feb Month)


generally i want to make Attendance register for the Sub employee of the Main.

so, please help me or guide me if any other solution is there expect Gridview in C#.

Thanks in advance....
Mitesh

解决方案

And the issue is?

For columns based on month:
Step:
1. Get current month
2. based on current month''s last day number, you can run a loop and add those many columns to grid/table
3. based on child person, you will have that many row. Based on what you say it sounds like will be empty for all days.

Combine and you have grid with those many columns and rows. Now, try out. I am sure there will be more to this. Add additional details, if you face issue, post specific issue.


Hi,

creat datatable object and column declartion then finally add that column to Row.

DataTable dtable = new DataTable();

dtable.Columns.Add(new DataColumn("Day1", typeof(string)));
           dtable.Columns.Add(new DataColumn("Day2", typeof(string)));
           dtable.Columns.Add(new DataColumn("Day3", typeof(string)));
           dtable.Columns.Add(new DataColumn("Day4", typeof(string)));
           dtable.Columns.Add(new DataColumn("Day5", typeof(string))); ..... 28 
 DataRow dr = dtable.NewRow();
 dr[0] = Datareader.GetValue(0).ToString();
                    dr[1] = Datareader.GetValue(1).ToString();-...........28
 dtable.Rows.Add(dr);


这篇关于在gridview中动态创建行和列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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