[VB]取出Gridview的TemplateField裡面textbox checkbox的值
實作gridview表格裡,將TemplateField裡元件(textbox , checkbox)值取出。
程式碼:
Public Sub Get_gv_control_data()
For Each row As GridViewRow In gv_screen_filter.Rows
For Each cell As TableCell In row.Cells
Dim controls As New List(Of Control)()
'Add controls to be removed to Generic List
For Each control As Control In cell.Controls
controls.Add(control)
Next
For Each control As Control In controls
Select Case control.GetType().Name
Case "TextBox"
Response.Write("<p>Text: " & TryCast(control, TextBox).Text & "/ID: " & TryCast(control, TextBox).ID & "</p>")
Exit Select
Case "CheckBox"
Response.Write("<p>Text: " & TryCast(control, CheckBox).Checked.ToString() & "/ID: " & TryCast(control, CheckBox).ID & "</p>")
Exit Select
End Select
Next
Next
Next
End Sub
實作結果:
列印出textbox的值與checkbox的Checked狀態和元件id
程式碼:
Public Sub Get_gv_control_data()
For Each row As GridViewRow In gv_screen_filter.Rows
For Each cell As TableCell In row.Cells
Dim controls As New List(Of Control)()
'Add controls to be removed to Generic List
For Each control As Control In cell.Controls
controls.Add(control)
Next
For Each control As Control In controls
Select Case control.GetType().Name
Case "TextBox"
Response.Write("<p>Text: " & TryCast(control, TextBox).Text & "/ID: " & TryCast(control, TextBox).ID & "</p>")
Exit Select
Case "CheckBox"
Response.Write("<p>Text: " & TryCast(control, CheckBox).Checked.ToString() & "/ID: " & TryCast(control, CheckBox).ID & "</p>")
Exit Select
End Select
Next
Next
Next
End Sub
實作結果:
列印出textbox的值與checkbox的Checked狀態和元件id
Text: False/ID: CheckBox1
Text:q /ID: TextBox1
Text:qw /ID: TextBox2
Text: qwe/ID: TextBox3
留言
張貼留言