使用for循环网格视图在auto生成中创建colun和rows [英] create colun and rows in auto generated using for loop grid view

查看:71
本文介绍了使用for循环网格视图在auto生成中创建colun和rows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建这样的网格视图

第一行应该是当前月份日期,如8月1日至31日





-----------------------------------------------

员工ID | 1 | 2 | 3 | 4 | ...... | 29 | 30 | 31 |

---------------------------------------- --------

1 | p | p | a | a | ...... | p | a | a |

---------------------------------------- --------

create grid view like this
first row should be current months dates like aug 1 to 31


-----------------------------------------------
staff id| 1 | 2 | 3 | 4 |......| 29 | 30 | 31 |
------------------------------------------------
1 | p | p | a | a |......| p | a | a |
------------------------------------------------

推荐答案

试试这个

您可以在高级的aspx中创建网格视图,或者在.cs中创建网格视图页面(代码未提供)



Try this
You can Create Grid view in aspx in advanced or Create gridview in .cs page (Code not provided for same)

DataTable dt = new DataTable();

for(i=0;i<32;i++) //To print date , Considering 31 days for month 
{
   dt.Columns.Add(i.ToString());
}
for(j=0;j<10;j++) // Considering 10 entries - For Rows 
{
   DataRow drow = dt.NewRow();
   for(k=0;k<32;k++)
   {
      //Your Logic
      if( k % 2 == 0)
         drow[k] = "P";
      else
         drow[k] = "A";

   }
   dt.Rows.Add(drow);
}

grdView.DataSource = dt;
grdView.DataBind();


你必须为此构建一个 DataTable



声明新的 DataTable 。然后运行一个循环,并为循环内的每个添加列。

添加列后,添加行。



然后将 DataTable 分配给 GridView
You have to build one DataTable for this.

Declare new DataTable. Then run a loop for all the days and add column for each inside the loop.
Now after adding the columns, add rows.

Then assign the DataTable to the GridView.


这篇关于使用for循环网格视图在auto生成中创建colun和rows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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