一张Aritcles表里,有一个PostTime字段,里面是记录的是DATETIME.NOW,那么,怎么实现如下的效果:
2008年十月
文章1
文章2
文章3
2008年九月
文章1
文章2
文章3
.....
2007年...
.....
2008年十月
文章1
文章2
文章3
2008年九月
文章1
文章2
文章3
.....
2007年...
.....
解决方案 »
- 50分求ASP.NET整合UCenter同步登陆DZ和UChome示例代码
- 我在本地上运行没问题,但部署到服务器上,就报找不到.cs文件错误
- digg 网站或者blog系统 每篇文章简介部分的缩略图 如何自动生成呢?
- asp.net怎么得到已经上传的大小
- 关于ffmpeg视频转换及切图的问题
- iframe子页面有时候显示不出来,怎么解决?
- 有点晕,点击LinkButton按钮弹出带参数的窗口没反应 !!!
- ASP.NET的优势究竟在哪里?
- ASP.net创建工程时出现错误!急!!求助!!
- 如何写客户端脚本操作 DataList,让其每次显示一条Tabel中的记录,不回发到服务器??C#能不能写客户脚本?
- [求助] SelectedRowStyle需要用什么方式来触发?
- 关于在.shtml文件中include .aspx页面问题?
from Aritcles
group by left(convert(char(8),PostTime,112),6)
order by 1 desc
protected override void Render(HtmlTextWriter writer)
{
DateTime oldDate = new DateTime(1990, 1, 1); Table table = (Table)GridView1.Controls[0];
foreach (GridViewRow row in GridView1.Rows)
{
DateTime newDate = Convert.ToDateTime(row.Cells[2].Text); //假定日期字段在GridView的第3列显示
if (newDate.Year != oldDate.Year || newDate.Month != oldDate.Month) // 如果两个日期的年、月不相同
{
int index = table.Rows.GetRowIndex(row); GridViewRow insertRow = new GridViewRow(index, index, DataControlRowType.DataRow, DataControlRowState.Normal);
TableCell cell = new TableCell();
cell.Text = newDate.Year + "年" + newDate.Month + "月";
cell.ColumnSpan = GridView1.Columns.Count;
insertRow.Cells.Add(cell);
table.Controls.AddAt(index, insertRow); oldDate = newDate;
}
}
base.Render(writer);
}
group by y,m
order by PostTime
group by y,m
order by PostTime
那么,怎么实现如下的效果: 2008年十月
文章的标题
文章的标题
文章的标题
2008年九月
文章的标题
文章的标题
文章的标题
.....
2007年...
.....
.aspx<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="uid" DataSourceID="SqlDataSource1" EmptyDataText="没有可显示的数据记录。"
onprerender="GridView1_PreRender">
<Columns>
<asp:BoundField DataField="ArticleCaption" HeaderText="标题" SortExpression="ArticleCaption" />
<asp:BoundField DataField="PostTime" HeaderText="日期"
SortExpression="PostTime" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:数据库连接字符串%>"
ProviderName="<%$ ConnectionStrings:数据库连接字符串.ProviderName %>"
SelectCommand="SELECT ArticleCaption, PostTime FROM [Aritcles] order by PostTime"
/>.cs
protected override void Render(HtmlTextWriter writer)
{
DateTime oldDate = new DateTime(1990, 1, 1); Table table = (Table)GridView1.Controls[0];
foreach (GridViewRow row in GridView1.Rows)
{
DateTime newDate = Convert.ToDateTime(row.Cells[1].Text); //假定日期字段在GridView的第2列显示
if (newDate.Year != oldDate.Year || newDate.Month != oldDate.Month) // 如果两个日期的年、月不相同
{
int index = table.Rows.GetRowIndex(row); GridViewRow insertRow = new GridViewRow(index, index, DataControlRowType.DataRow, DataControlRowState.Normal);
TableCell cell = new TableCell();
cell.Text = newDate.Year + "年" + newDate.Month + "月";
cell.ColumnSpan = GridView1.Columns.Count;
insertRow.Cells.Add(cell);
table.Controls.AddAt(index, insertRow); oldDate = newDate;
}
}
base.Render(writer);
}