[.NET] 在GridView中呼叫函數

看板Visual_Basic作者 (b8888)時間12年前 (2013/05/24 01:25), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
請輸入專案類型(網站專案或者應用程式專案):asp.net (vb) 各位大大好,小弟有一個問題 即在gridview中可否有類似button.click的功能 是這樣的~~ 小弟有一個需求是在gridview中加入一個button 當user去按該列的button 後執行一個自訂的fuction ex: gridview 顯示如下: yymm seq_no 欄位略... 執行function 10201 10 btnOut (button ) 10202 10 10203 10 10201 20 10202 20 ............. 其中btnOut 已轉成template 了 以下是程式 其中funOutgrieview時每執行列就會執行一次 請問有沒有什麼方法是,當我按下"btnOut"時才會去執行funOut 先謝謝您的回答 Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound Dim cmdButton As Button = CType(e.Row.FindControl("btnMod"), Button) Dim cmdButton2 As Button = CType(e.Row.FindControl("btnOut"), Button) If e.Row.RowType = DataControlRowType.DataRow Then Dim bt1, bt2, bt3 As New Button bt1 = CType(e.Row.Cells(2).FindControl("btnMod"), Button) bt2 = CType(e.Row.Cells(3).FindControl("btnOut"), Button) If bt1.ID = "btnMod" Then Dim lb1, lb2 As New Label lb1 = CType(e.Row.FindControl("Label1"), Label) lb2 = CType(e.Row.FindControl("Label2"), Label) cmdButton.OnClientClick = "javascript:window.open('a123OB.aspx?id_no=" + lb1.Text.Trim & "&title_nm=" & lb2.Text.Trim + "',null,'status=yes,left=350,top=200,width=400,height=250')" End If If bt2.ID = "btnOut" Then Dim lb1, lb2 As New Label lb1 = CType(e.Row.FindControl("Label1"), Label) lb2 = CType(e.Row.FindControl("Label2"), Label) funOut( lb1.text ,lb2.text) End If End If End Sub -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.47.214.196

05/24 04:50, , 1F
寫一個ButtonField,或在TemplateField內寫button
05/24 04:50, 1F
文章代碼(AID): #1Hdb3tWl (Visual_Basic)
文章代碼(AID): #1Hdb3tWl (Visual_Basic)