[.NET] 抓取GridView的TemplateField的Label

看板Visual_Basic作者 (口苗)時間8年前 (2015/10/29 17:20), 編輯推噓0(006)
留言6則, 2人參與, 最新討論串1/1
請輸入專案類型(網站專案或者應用程式專案):ASP.NET VB.NET 請教前輩 我想要抓取 GridView 的 TemplateField 中的 Label 控制項的值 可是一直失敗,也查了好多資料,一直沒辦法成功 目的是GridView某欄位(值只有0.1.2) 顯示時我可以改塞入不同的對映資料 我是在RowDataBound事件中作抓取動作,有試過下列抓法 Dim lb As Label lb = CType(GridView1.Rows(e.RowIndex).Cells(5).FindControl("Label1"), Label) 但是 e.RowIndex 不是這事件的成員 請問我是事件選擇錯誤了嗎? (有做過沒有TemplateField的抓取e.Row.Cells(5).Text 就沒問題) 還是語法錯誤了? 謝謝~ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.124.54.20 ※ 文章網址: https://www.ptt.cc/bbs/Visual_Basic/M.1446110428.A.735.html

10/29 21:02, , 1F

10/29 21:12, , 2F

10/30 09:46, , 3F
感謝~
10/30 09:46, 3F

10/30 09:47, , 4F
補上For i As Integer = 0 To GridView1.Rows.Count -1
10/30 09:47, 4F

10/30 09:48, , 5F
GridView1.Rows(i).Cells(0).FindControl("Label1")
10/30 09:48, 5F

10/30 09:49, , 6F
且不能加上 e.Row.RowType 的判斷 不然列數會跑掉
10/30 09:49, 6F
文章代碼(AID): #1MCUJSSr (Visual_Basic)