We can add AutoNumber column by using Container.DataItemIndex property in html markup of the Gridview.

Here's the sample html markup for the page
<title>Auto Number Cloumn in GridView </title> </head> <body> <form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" PageSize="6" AlternatingRowStyle-BackColor="#006699" AlternatingRowStyle-ForeColor="#FFFFFF" > <Columns> <asp:TemplateField HeaderText="Serial Number"> <ItemTemplate> <%# Container.DataItemIndex + 1 %> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> <asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [Name], [Location] FROM [Details]"> </asp:SqlDataSource>
Hope this helps
It is Really helpful. Thank you.
ReplyDeleteU just saved me hours. TQ!!!
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeletethank dude....u really helped me out frm tension.....tc
ReplyDeletehi its great can u explain with more examples
ReplyDeleteOui, c'est la rГ©ponse intelligible prematuree achat cialis en ligne
ReplyDeleteGenius man !
ReplyDeletehow to delete row in datatable and bind the datatable into datagrid
ReplyDeleteIt was hitherto a subject of declaration to whether or not being had to contain a drift to be lived. It now becomes obvious, on the contrary, that it will-power be lived all the think twice if it has no meaning.
ReplyDeleteAnd you in the long run get to a consensus, where you get a sense of what in effect ought to be done, and then they entrust it to me and then I draw it. I without fail delineate it in the drift, the theoretical sense.
ReplyDeleteThank u Very much.........
ReplyDeleteI think I just have been told about this issue
ReplyDeleteat pub 1 day ago by a mate, but at that moment
it didn't caugh my attention.
I think I allready have been told about this issue
ReplyDeleteat work 1 day ago by a colleague, but at that moment
it didn't caugh my attention.
Gr8 Work,
ReplyDeleteThanx lol
Ch@n*83
thank you dear friend, it really helped, really appreciate your help.
ReplyDeletethis is really gud...thank u
ReplyDeleteThank u Very much.........
ReplyDeletehi thanks for your posts it really helped me a lot.Could u plz do one more favour for me.Plz poat an article abot "how to add a new in GridView without using DataSource Controls. "
ReplyDelete