• 全部
  • .NET Framework
  • ASP
  • Web Services
  • .NET互联网桌面应用
  • VB
  • 图表区
  • 分析与设计
  • 组件/控件开发
  • AppLauncher
  • 问答

我用了datagrid的模版列,请问我怎么用不同色(比如红色)显示今天的记录,

nicemood 2004-11-04 10:19:04
网站是这样的zhaobiao.scol.com.cn
当日与今天日期相同的,我用红色显示,请问应如何做呢?谢谢
...全文
169 点赞 收藏 18
写回复
18 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
nicemood 2004-11-11
应为If e.Item.ItemIndex >= 0 Then
回复
nicemood 2004-11-05
up,up,up,大家帮帮忙吧
回复
nicemood 2004-11-05
日期字段为datetime型
回复
nicemood 2004-11-05
Truly(今儿个冲级) (
这个编译没有报错,但是没有作用.

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound

If e.Item.ItemIndex > 0 Then
Dim drv As DataRowView
drv = e.Item.DataItem
Dim thisdate As DateTime
thisdate = drv("add_time")

If DateTime.Now.ToString("yyyy-MM-dd") = thisdate.ToString("yyyy-MM-dd") Then
e.Item.Cells(1).ForeColor = Color.Red
End If

End If

End Sub


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
Try
Dim myconn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("conn"))
Dim mycmd As String = "select id,Project_name,add_time from bxgg_info ORDER BY add_time DESC"
Dim dap As SqlDataAdapter = New SqlDataAdapter(mycmd, myconn)
Dim dst As DataSet
dst = New DataSet
dap.Fill(dst)
DataGrid1.DataSource = dst.Tables(0).DefaultView
DataGrid1.DataBind()

Catch ex As Exception
Response.Write(ex)


End Try

End Sub


<asp:datagrid id="DataGrid1" runat="server" Width="100%" BorderWidth="1px" BorderColor="#DEDFDE"
BackColor="Khaki" ForeColor="White" GridLines="Vertical" BorderStyle="None" CellPadding="4" ShowHeader="False"
AutoGenerateColumns="False" AllowPaging="True" PageSize="12">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#CE5D5A"></SelectedItemStyle>
<AlternatingItemStyle BackColor="White"></AlternatingItemStyle>
<ItemStyle Font-Size="12px" BackColor="WhiteSmoke"></ItemStyle>
<HeaderStyle Font-Size="12px" Font-Bold="True" ForeColor="White" BackColor="#6B696B"></HeaderStyle>
<FooterStyle BackColor="#CCCC99"></FooterStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:HyperLink runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.project_name") %>' NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.id", "ipb_show.aspx?id={0}") %>' Target="_blank">
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderStyle></HeaderStyle>
<ItemStyle ForeColor="#000066" Width="80px"></ItemStyle>
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.add_time", "{0:d}") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.add_time", "{0:d}") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Visible="False" HorizontalAlign="Right" ForeColor="Black" BackColor="#F7F7DE" Mode="NumericPages"></PagerStyle>
</asp:datagrid>

回复
zhangzs8896 2004-11-05
DataGrid1_ItemDataBound事件里写!

回复
nicemood 2004-11-05
kao,为什么都一样的却只红了一个呢?????
回复
SeeSunSet 2004-11-05
别忘了,它是支持HTML的.所以.你可以在值上做文章.
回复
Truly 2004-11-05
Private Sub DataGrid1_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If e.Item.ItemIndex > 0 Then
Dim drv As DataRowView
drv = e.Item.DataItem
If DateTime.Now.ToString("yyyy-MM-dd") = drv("日期字段") Then
e.Item.Cells(1).ForeColor = Color.Red

End If

End If


End Sub
回复
nicemood 2004-11-04
: zzcwhq(zzcwhq)

能具体点吗?
回复
zzcwhq 2004-11-04
在你绑定的sql语句里处理,很简单的,
select '<font color=red>'+field1+'</font>' as newField from ...
回复
yichuan1982 2004-11-04
顶一下
回复
nicemood 2004-11-04
能详细说明一下吗?是在

Private Sub DataGrid1_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DataBinding


End Sub
中写吗?
能用VB写一下嘛,谢谢了
回复
zhn0410 2004-11-04
占个位学习。
回复
spland 2004-11-04
brightheroes(闭关|那一剑的风情) 正解
回复
brightheroes 2004-11-04
我倒

if(e.Item.ItemIndex > -1)
{
DataRowView drv = (DataRowView)e.Item.DataItem;
if(DateTime.Now.ToString("yyyy-MM-dd") == drv["你的时间字段"].ToString())
{
e.Item.Cells[2].ForeColor = Color.Red;
}
}
回复
brightheroes 2004-11-04
数据绑定的时候

if(e.Item.ItemIndex > -1)
{
DataRowView drv = (DataRowView)e.Item.DataItem;
if(DateTime.Now.ToString("yyyy-MM-dd") == drv["你的时间字段"].ToString())
{
e.Item.BackColor = Color.Red;
}
}
回复
nicemood 2004-11-04
用红色显示日期
回复
nicemood 2004-11-04
自已UP一下子了
回复
发帖
.NET技术社区
创建于2007-09-28

5.8w+

社区成员

.NET技术交流专区
申请成为版主
帖子事件
创建了帖子
2004-11-04 10:19
社区公告
暂无公告