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 :)

Text Editor Tips: Some Useful Brackets Extension

Brackets  is an open source and free-to-use text editor and primarily being used by web developers and designer. I mainly use Brackets for d...