作者karoro (出现了!!!)
看板Visual_Basic
标题Re: [.NET] 新增公告旁边的new图片
时间Mon May 14 10:49:07 2007
※ 引述《fumizuki (蒙面加菲狮)》之铭言:
: ※ 引述《karoro (出现了!!!)》之铭言:
: : 各位先进好 小弟又来请教各位了
: : 小弟目前在做公告系统 是用Gridview连资料来源 再去编辑要显示的栏位
: : 例如 │ 公告日期 │ 标题 │ 公告人 │
: : 就成了一个很简单的公告系统 但小弟想新增一笔新资料时 如果是当天新增
: : 就会在标题的旁边出现一个new的图案 我试过很多方法都没用 不然就是出现错误
: : 不知道各位先进是否有比较好的方法呢? 谢谢各位指教
: <Columns> <!-- 在此区块加入这段aspx标签(放在Columns的开头) -->
: <asp:TemplateField HeaderText="">
: <ItemTemplate>
: <asp:Image ID="img1" runat="server" />
: </ItemTemplate>
: </asp:TemplateField>
: </Columns>
: Protected Sub GridView1_RowCreated(ByVal sender As Object, _
: ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
: Handles GridView1.RowCreated
: If e.Row.RowType = DataControlRowType.DataRow And _
: (e.Row.RowState = DataControlRowState.Normal Or _
: e.Row.RowState = DataControlRowState.Alternate) Then
: Dim img1 As Image = CType(e.Row.Cells(0).Controls(0), Image)
: img1.ImageUrl = "images/new.gif" '改成你的图档路径
: End If
: End Sub
感谢版主大人的指导 但我用了之後发生一些问题 因为我还要判断发布日期
是否为当日日期 如果是的话 就显示图片 所以又加了一段
Dim t1 As Label = CType(e.Row.Cells(0).Controls(0), Label)
if t1.text = 当天日期 then
图片出现
end if
但问题来了 它会出现错误: 指定的引数超出有效值的范围。参数名称: index
我的label是放在第一个栏位 而且里面只放一个label 没有其他物件了
所以e.Row.Cells(0).Controls(0)应该是对的 怎麽会出现错误呢?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 163.29.137.250