作者fumizuki (蒙面加菲狮)
看板Visual_Basic
标题Re: [.NET] 新增公告旁边的new图片
时间Mon May 14 12:47:53 2007
※ 引述《karoro (出现了!!!)》之铭言:
: ※ 引述《fumizuki (蒙面加菲狮)》之铭言:
: : <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)
改成
Dim img1 As Image = CType(e.Row.FindControl("img1"), 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)应该是对的 怎麽会出现错误呢?
前面应该是有被 GridView 自动加入一些控制项,是不会显示在ie 画面上的
--
▃▅▇▆▄ ▆▂▃ `
逝去感情如何能留住,半点痴情遗留殊不易,██▅▇▄▃ ▇▃▂" .
█████████▃i ▁▄▇
更多凄凄惨惨的遭遇…………██▆▃ █▅▆▃ˍ▄*
◢ ▂█▄▇▅▂▌.
我不知道,王~八~蛋~~! ▂▆███ █▄▃ 。fumizuki。Check。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 60.248.175.60