要在ASP.NET中访问DataGrid中所有控件的值,可以遍历DataGrid中每个控件:下面就是实现这一功能的ASPx代码和脚本代码【VB.NET】:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="DataGridAccessValues.ASPx.vb"
Inherits="ASPxWeb.DataGridAccessValues"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
</HEAD>
<body>
<form runat="server" ID="Form1">
<ASP:DataGrid id="MyDataGrid" runat="server" Width ="100%" AutoGenerateColumns="False">
<ItemStyle verticalalign="Top"></ItemStyle>
<Columns>
<ASP:BoundColumn DataField="Name" HeaderText="Name"></ASP:BoundColumn>
<ASP:TemplateColumn HeaderText="Age">
<ItemTemplate>
<ASP:TextBox id="AgeField" Columns="5" Text='<%# DataBinder.Eval(Container.DataItem,"Age") %>'
runat="server"></ASP:TextBox>
</ItemTemplate>
</ASP:TemplateColumn>
<ASP:TemplateColumn HeaderText="Graduate">
<ItemTemplate>
<ASP:CheckBox id="IsGraduateField" Checked='<%# DataBinder.Eval(Container.DataItem,"IsGraduate") %>'
runat="server"></ASP:CheckBox>
</ItemTemplate>
</ASP:TemplateColumn>
<ASP:TemplateColumn HeaderText="Skills">
<ItemTemplate>
<ASP:CheckBoxList id="CheckBoxList1" runat="server">
<ASP:ListItem Value="C#" Selected="true">C#</ASP:ListItem>
<ASP:ListItem Value="C++">C++</ASP:ListItem>
<ASP:ListItem Value="VB">VB</ASP:ListItem>
<ASP:ListItem Value="SQL Server" Selected="true">SQL Server</ASP:ListItem>
</ASP:CheckBoxList>
</ItemTemplate>
</ASP:TemplateColumn>
<ASP:TemplateColumn HeaderText="Experience">
<ItemTemplate>
<ASP:RadioButtonList id="RadioButtonList1" runat="server">
<ASP:ListItem Value="1">1 Year</ASP:ListItem>
<ASP:ListItem Value="3">3 Year</ASP:ListItem>
<ASP:ListItem Value="5" Selected="true">5 Year</ASP:ListItem>
<ASP:ListItem Value="10">10 Year</ASP:ListItem>
</ASP:RadioButtonList>
</ItemTemplate>
</ASP:TemplateColumn>
<ASP:TemplateColumn HeaderText="Degree">
<ItemTemplate>
<ASP:DropDownList id="DropDownList1" runat="server">
<ASP:ListItem Value="HighSchool">HighSchool</ASP:ListItem>
<ASP:ListItem Value="Graduate" Selected="true">Graduate</ASP:ListItem>
<ASP:ListItem Value="Masters">Masters</ASP:ListItem>
<ASP:ListItem Value="PHD">PHD</ASP:ListItem>
</ASP:DropDownList>
</ItemTemplate>
</ASP:TemplateColumn>
</Columns>
</ASP:DataGrid>
<br>
<ASP:Button id="GetValues" onclick="GetValues_Click" runat="server" Text="GetValues"></ASP:Button>
<br>
<ASP:Label id="ResultField" runat="server"></ASP:Label>
</form>
</body>
</HTML>