如何在GridView中仅显示天(1、2、3、4,最多30或31或28) [英] How to show only Days (1,2,3,4 upto 30 or 31 or 28) in gridview

查看:67
本文介绍了如何在GridView中仅显示天(1、2、3、4,最多30或31或28)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据月份和年份显示天数.这个月和一年是
显示在Dropdownlist中.当我选择月份和年份时,相应的日期将显示在GridView中.

I want show days according to the month and year. This month and year are
displayed in a Dropdownlist. When I select the month and year then the appropriate days are displayed in the GridView.

推荐答案

您可以找到以下月份中的日期.

You can find the days in a month as followng.

DateTime.DaysInMonth(year, month);



要绑定网格,请使用以下代码



To bind the grid use following code

private void Bind(int year, int month)
	{
		int days = DateTime.DaysInMonth(year, month);
		int[] daysArray = new int[days];
		for (int i = 0; i < days; i++)
		{
			daysArray[i] = i + 1;
		}
		GridView1.DataSource = daysArray;
		GridView1.DataBind();

	}


这篇关于如何在GridView中仅显示天(1、2、3、4,最多30或31或28)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆