Thursday, November 29, 2012

ASP.NET Tips : How To Give Easy Row Number to DataGridView or DataGrid

I find It very annoying when adding row number to a query result, espesially when you're working with different RDMS like Oracle or SQL Server. They have their own syntax for row numbering. But when you use that in a GridView or DataGrid, it will be a piece of cake. You can try using this technique in just like example :


<Columns>
<asp:TemplateColumn HeaderText="No.">
    <ItemTemplate>
<asp:Label runat="server" ID="LabelNumber" 
Text="<%# Grid1.PageSize*Grid1.currentPageindex + Container.ItemIndex+1%>">
</asp:Label>
</ItemTemplate>     
</asp:TemplateColumn>
</Columns>

Add a new column for your Row number. And you will find Grid1 is the ID of your GridView or DataGrid.

Here's give it a try :)

No comments:

Post a Comment

Tips: How to ssh to your Digitalocean server without password

If you are tired of being asked for a password when accessing your remote droplet servers in Digitalocean, you might consider adding an rsa ...