Visit the value of all controls in the DataGrid in ASP.NET

xiaoxiao2021-03-05  19

To access the values ​​of all controls in the DataGrid in the ASP.NET, you can traverse each control instance 1 (to Mencius E chapters): <% @ page language = "VB" autoeventwireup = "codebehind =" DataGridAccessValues. aspx.vb "inherits =" aspxweb.dataGridaccessValues ​​"%>

Back-end code: Imports System.Collections Public Class DataGridAccessValues ​​Inherits System.Web.UI.Page Protected WithEvents MyDataGrid As System.Web.UI.WebControls.DataGrid Protected WithEvents GetValues ​​As System.Web.UI.WebControls.Button Protected WithEvents ResultField As System .Web.ui.WebControls.Label #Region "WEB Form Designer Generated Code" 'This call is required for the web form designer.

PRIVATE SUB Initialization () End Sub Private Sub Page_init (Byval E AS System.EventArgs) Handles mybase.init 'Codegen: This method call is required by the Web Form Designer' Do not use the code editor Modify it.

InitializeComponent () End Sub #End Region Public Sub GetValues_Click (ByVal sender As Object, ByVal e As System.EventArgs) Handles GetValues.Click Dim Result As String = "" Dim dataGridItem As DataGridItem For Each dataGridItem In MyDataGrid.Items Dim Name As String = dataGridItem.Cells (0) .Text Dim AgeField As TextBox = dataGridItem.FindControl ( "AgeField") Dim Age As Integer = System.Convert.ToInt64 (AgeField.Text) .ToString () Dim IsGraduateField As CheckBox = dataGridItem.FindControl ( "IsGraduateField") Dim IsGraduate As Boolean = IsGraduateField.Checked Dim Skills As String = "" Dim item As ListItem Dim CheckBoxList1 As CheckBoxList = dataGridItem.FindControl ( "CheckBoxList1") For Each item In CheckBoxList1.Items If item.Selected Then Skills = Skills item.Value "," End If Next Skills = Skills.TrimEnd ( ",") Dim RadioButtonList1 As RadioButtonList = dataGridItem.FindControl ( "RadioButtonList1") Dim Experience As String = RadioButtonList1.SelectedItem.Text Dim DropDownList1 As DropDownList = DataGridItem.FindControl ( "DropDownList1") Dim Degree As String = DropDownList1.SelectedItem.Text Result = Result Name Result = Result "[Age:" Age.ToString () "]" Result = "" If IsGraduate THEN RESULT = "Expected," Else Result = "has no graduation," Endiff = "skill:" Skills "," Result = "experience:" experience ", and" Result = "Degree:" DEGREE ". "Result ="

"Next ResultField.Text = Result End Sub Private Sub Page_Load (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code is initialized page If Not Page.IsPostBack Then Dim data As here ArrayList = new arraylist () Data.Add (New Person ("Net_LOVER", 33, TRUE) Data.Add (New Person ("Mencius E Chapter", 28, True) Data.Add ("Wonderful World ", 20, false) Data.Add (New Person (" XML Development ", True) MyDataGrid.DataSource = data mydatagrid.database = data mydatagrid.database Person Private _name As String Private_age as String Private_age as STRING Integer Private _IsGraduate As Boolean Public Sub New (ByVal Name As String, ByVal Age As Integer, ByVal IsGraduate As Boolean) _Name = Name _Age = Age _IsGraduate = IsGraduate End Sub Public Property Name () As String Get Return _Name End Get Set (ByVal Value As String) _Name = Value End Set End Property Public Property Age () As Integer Get Return _Age End Get Set (ByVal Value As Integer) _Age = Value End Set End Property Public Property IsGraduate () As Boolean Get Return _ISGRADUATE END GET SET (BYVAL VALUE AS BOOLEAN) _ISGRADUATE = Value End End Property End Class C # example code: <% @ page language = "c #"%> <% @ Import namespace = "system.collections"%>