<asp:TemplateField HeaderText="aa"> <ItemTemplate> <asp:Label ID="aa" runat="server" Width="50px" Text='<%#Bind("aa") %>'></asp:Label> </ItemTemplate> </asp:TemplateField>For i As Integer = 0 To GridView1.Rows.Count - 1 Dim row As GridViewRow = GridView1.Rows(i) Dim aa as string="" aa=DirectCast(row.Cells(0).FindControl("aa"), Label).Text End If Conn.Close() Next
看见一个牛人大概是这样写的string result=null; foreach (DataControlField col in this.GridView1.Columns) if (col is BoundField) { var col1 = (BoundField)col; result = col1.DataField; }
<asp:TemplateField HeaderText="aa">
<ItemTemplate>
<asp:Label ID="aa" runat="server" Width="50px" Text='<%#Bind("aa") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>For i As Integer = 0 To GridView1.Rows.Count - 1
Dim row As GridViewRow = GridView1.Rows(i)
Dim aa as string=""
aa=DirectCast(row.Cells(0).FindControl("aa"), Label).Text
End If
Conn.Close()
Next
你可以通过这两种方式中的一种就可以拿到了
好像是这样grivew.rows[当前行的索引].cell[你要拿的列的索引]
foreach (DataControlField col in this.GridView1.Columns)
if (col is BoundField)
{
var col1 = (BoundField)col;
result = col1.DataField; }