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

Try this ,

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



Thanks,
 
Share this answer
 
Comments
MayurUdupa 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 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)



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