前台DataGrid:
<asp:DataGrid ID="Data" runat="server" AutoGenerateColumns="False" CellPadding="0"
Font-Bold="False" OnItemCommand="Data_ItemCommand" OnItemDataBound="Data_ItemDataBound"
PageSize="5" Width="100%">
<Columns>
<asp:BoundColumn DataField="aaa"></asp:BoundColumn>
<asp:BoundColumn DataField="bbb"></asp:BoundColumn>
<asp:BoundColumn DataField="ccc"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
后台cs:
DataTable dt = new DataTable();
dt.Columns.Add("aaa");
dt.Columns.Add("bbb");
dt.Columns.Add("ccc");
dt.Rows.Clear();
DataRow dr = dt.NewRow();
dr[0] = "aaaaa";
dr[1] = "bbbbb";
dr[2] = "ccccc";
dt.Rows.InsertAt(dr,0);
axDgdData.DataSource = dt;
axDgdData.DataBind();
int i = dt.Columns.Count;
Response.Write(i.ToString());