Wednesday, May 25, 2005

 

Automatic numbering of the columns in a DataGrid

For my ASP.NET DataGrid problem that I mentioned earlier, I will start off by saying how I got the rows to automatically number themselves. I know this is posted lots of places elsewhere, but I'll put it here quickly anyway.

I just added a column to the DataGrid that looks like this:
  <asp:TemplateColumn HeaderText="No.">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "ItemIndex")+1 %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" Text='<%# MyDataGrid.Items.Count+1 %>'>
</asp:Label>
</FooterTemplate>
<EditItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "ItemIndex")+1 %>'>
</asp:Label>
</EditItemTemplate>
</asp:TemplateColumn>

This page is powered by Blogger. Isn't yours?