Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0ASP.NET
I have to select month and year of a calendar, columns must be automatically generate in grid view with respect to the no of days of selected month and year using asp.net with C#.
Posted 11-Oct-12 23:50pm
Comments
TheCoolCoder at 12-Oct-12 6:33am
   
Please clarify what exactly you need to do "columns must be automatically generate in grid view with respect to the no of days of selected month and year" : not able understand your requirement.
MayurUdupa at 13-Oct-12 5:01am
   
Query is: When i select a month "e.g June, June have 30 days", it should generate the 30 columns in gridview. I got the number of days in a month. How to generate those 30 columns in gridview.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try this ,
 
 
DateTime Today = DateTime.Now;
int Year = Today.Year;
int Month = Today.Month;
int Days = DateTime.DaysInMonth(Year, Month);
GridView_Name.Columns.Add(Days);
 
 

Thanks,
  Permalink  
Comments
MayurUdupa at 13-Oct-12 8:02am
   
I already tried this but its not working.. int month = Calendar1.SelectedDate.Month; int year = Calendar1.SelectedDate.Year; int days=DateTime.DaysInMonth(year, month); for (int i = 1; i <= days; i++) { //using this loop can i generate columns? }
Afzal Shaikh at 14-Oct-12 6:32am
   
no need to generate loop , just use this below code to generate columns in grid view GridView_Name.Columns.Add(Days); // it ll add columns to grid view ,Days is the number of columns it will automatically add the number of columns you provide in Add Function , in this case days.

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Guruprasad.K.Basavaraju 490
1 Shai Vashdi 474
2 Sergey Alexandrovich Kryukov 291
3 OriginalGriff 135
4 praveen_07 115
0 Sergey Alexandrovich Kryukov 9,185
1 OriginalGriff 5,335
2 Peter Leow 4,040
3 Maciej Los 3,540
4 Abhinav S 3,308


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 12 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid