gridview 列值相同问题
gridview 如果列值相同 比如author date
tom 2007-8-1
tom 2007-8-1
tom 2008-8-1
tom 2006-5-1
就将date值相同的两行加粗
怎么写事件 --------------------编程问答-------------------- mark --------------------编程问答-------------------- 判断哪两行相同挺麻烦的。 --------------------编程问答-------------------- 没有人会!大家讲讲呢 --------------------编程问答-------------------- 再顶 --------------------编程问答-------------------- 帮顶一下,关注 --------------------编程问答-------------------- 这个没有想过 啊,帮顶了。 --------------------编程问答-------------------- 先用SQL的分组语句增加一个是否是重复的标志字段Status:
string sql = @"Select Book.author,Book.date,Status
From Book,(Select author,date, Case When Count(*)>1
Then 'Double'
Else 'Single'
End
As 'Status'
From Book Group By author,date) As Book2
Where Book.author=Book2.author
And Book.date=Book2.date";
<asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="author" HeaderText="author" />
<asp:BoundField DataField="date" HeaderText="date" />
</Columns>
</asp:GridView>
然后在行绑定结束时,判断Status字段,如果是Double,那么就给该行添加加粗Style。
protected void GridView1_RowDataBound ( object sender, GridViewRowEventArgs e )
{
if ( e.Row.RowType == DataControlRowType.DataRow )
{
if ( DataBinder.Eval( e.Row.DataItem, "Status" ).ToString() == "Double" )
{
e.Row.Attributes.Add ( "style", "font-weight:bold" );
}
}
}
--------------------编程问答-------------------- 五星的就是牛!试试看 --------------------编程问答-------------------- SQL 处理这个不错
绑定的时候可能不用这么麻烦 --------------------编程问答-------------------- 7楼的改个
提高性能
<%# ((DataRowView)Container.DataItem).Row["Status"] %>
补充:.NET技术 , ASP.NET