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

Finally, C# 9 record, the equivalent of Scala's case class

While C# is a wonderful programming language, there is something that I would like to see to make our life programmer easier. If you are fam...