Click here to Skip to main content
15,896,489 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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.
 
Share this answer
 
Comments
[no name] 6-Feb-13 1:18am    
yes sandeep mewara you are right but which way i create dynamically created row and column.
Sandeep Mewara 6-Feb-13 1:23am    
Try using:
datatable.Columns.Add();
datatable.Rows.Add(dataRow);
Hi,

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

DataTable dtable = new DataTable();
C#
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);
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900