This example explains how to Add AutoNumber Column In GridView Or DataList In ASP.NET 2.0,3.5,4.0 Using C# And VB.NET. Several times we need to display Auto Number or serial number for Rows records in gridview or other similar controls in ASP.NET.
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
AutoNumber Column In GridView DataList ASP.NET
Posted by
Unknown
If you like this post than join us or share
Subscribe to:
Post Comments (Atom)
18 comments:
It is Really helpful. Thank you.
U just saved me hours. TQ!!!
This comment has been removed by a blog administrator.
thank dude....u really helped me out frm tension.....tc
hi its great can u explain with more examples
Oui, c'est la rГ©ponse intelligible prematuree achat cialis en ligne
Genius man !
how to delete row in datatable and bind the datatable into datagrid
It 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.
And 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.
Thank u Very much.........
I think I just have been told about this issue
at 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
at work 1 day ago by a colleague, but at that moment
it didn't caugh my attention.
Gr8 Work,
Thanx lol
Ch@n*83
thank you dear friend, it really helped, really appreciate your help.
this is really gud...thank u
Thank u Very much.........
hi 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. "
Post a Comment