Home > ASP.Net > Add Auto Numbering with DataList and Gridview

Add Auto Numbering with DataList and Gridview


Try this example:

http://blog.krisvandermast.com/AutonumberingASPNETGridControls.aspx

with dataList

<asp:TemplateColumn>

       <ItemTemplate>

            <%# Container.DataSetIndex + 1 %>

       </ItemTemplate>

</asp:TemplateColumn>

 

with GridView

<asp:TemplateField>

   <ItemTemplate>

      <%# Container.DataItemIndex + 1 %>

   </ItemTemplate>

</asp:TemplateField>

//——- or ————-

<asp:TemplateField HeaderText="Sl. No." HeaderStyle-Font-Bold="true" HeaderStyle-ForeColor="Black">

<ItemTemplate>

<%# ( ( ( GridView ) ( ( GridViewRow ) Container ).Parent.Parent ).PageIndex )*( ( GridView ) ( ( GridViewRow ) Container ).Parent.Parent ).PageSize+Container.DataItemIndex+1 %>
</ItemTemplate>

</asp:TemplateField>

Good Luck

Advertisements
Categories: ASP.Net
  1. June 19, 2010 at 6:15 am

    Above code for datalist is incorrenct.. please look at this..

    its correct and works for me

  2. June 19, 2010 at 6:16 am

    Use Container.DataSetIndex + 1

  3. yasserzaid
    June 20, 2010 at 3:56 pm

    @Hitesh Riziya :- yes your way is work too

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: