※ 引述《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