12,298,927 members (49,596 online)
Rate this:
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 11-Oct-12 23:50pm
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.

Rate this:

## Solution 1

Try this ,

```DateTime Today = DateTime.Now;
int Year = Today.Year;
int Month = Today.Month;
int Days = DateTime.DaysInMonth(Year, Month);
```

Thanks,
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.

Top Experts
Last 24hrsThis month
 ppolymorphe 360 OriginalGriff 344 CHill60 172 George Jonsson 160 CPallini 130
 OriginalGriff 9,615 ppolymorphe 5,736 CHill60 5,452 Karthik Bangalore 5,031 Richard MacCutchan 4,874