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