Click here to Skip to main content
12,298,927 members (49,596 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#2.0 C# ASP.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 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

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 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160525.2 | Last Updated 12 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100