嗨,我有以下网格视图
<asp:GridView ID="grdSettings" runat="server" Height="400px" Width="100%"
AutoGenerateColumns="false" >
<Columns>
<asp:TemplateField HeaderText="XYZ" BoundFieldName="XYZTypeName">
<ItemTemplate>
<asp:Label ID="lblCustomerName" runat="server" Text='<%# Bind("CustomerName") %>'>
</asp:Label>
<asp:Label ID="lblCostumerId" runat="server" Text='<%#Bind("CustomerId") %>'></asp:Label>
</asp:TemplateField>
</Columns>
</asp:GridView>
受客户列表约束,类如下
Class Customer
{
public string CustomerName { get; set; }
public int CustomerId { get; set; }
}
现在在名为 GetGridStuff() 的方法上,我需要在每一列中迭代并获取绑定到模板字段中控件的类型。例如,在模板字段中的第一个控件的情况下
<asp:Label ID="lblCustomerName" runat="server" Text='<%# Bind("CustomerName") %>' >
</asp:Label>
我需要知道它包含什么类型的属性数据,在本例中是 CustomerName。我需要在运行时动态获取它,以便在不知道该网格结构的程序的一部分中编写代码。我有网格对象,我可以访问所有属性。