Create sequance no in asp data grid or grid view

To create sequance no in asp data grid, just add a templace colum and fill with syntax :
<%#grd.CurrentPageIndex * grd.PageSize + Container.ItemIndex + 1 %>
Here the data grid sample :


And the result look :

On grid view we can use this way,

Add a template field column and create a label control inside the template field. The number will fill in from back code on event RowCreated.

And add come code :

Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

   protected void view_RowCreated(object sender,

   GridViewRowEventArgs e)


      if (e.Row.RowType == DataControlRowType.DataRow)


         Label lblNo = (Label)e.Row.FindControl("lblNo");

         lblNo.Text = e.Row.RowIndex.ToString();



Grid view result look :



Share this post: | | | |
Published Thursday, December 4, 2008 3:37 PM by ekasinggih
Filed under: ,


No Comments
Powered by Community Server (Commercial Edition), by Telligent Systems