<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Data Presentation Controls</title><link>http://forums.asp.net/24.aspx</link><description>ASP.NET data-bound controls such as the DataGrid, DataList, GridView, FormView, DetailsView, and Repeater Controls.  &lt;a href="http://aspadvice.com/SignUp/list.aspx?l=23&amp;c=17" target="_blank"&gt;Email List&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: displaying gridview row index number</title><link>http://forums.asp.net/thread/1759054.aspx</link><pubDate>Mon, 18 Jun 2007 07:36:47 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1759054</guid><dc:creator>XIII</dc:creator><author>XIII</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1759054.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=1759054</wfw:commentRss><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I also wrote an article about it for the 4 different data controls: repeater, datalist, datagrid and gridview: &lt;a class="TitleLinkStyle" href="http://blog.krisvandermast.com/AutonumberingASPNETGridControls.aspx" target="_blank" rel="bookmark"&gt;Autonumbering ASP.NET grid controls.&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Grz, Kris.&lt;/p&gt;</description></item><item><title>Re: displaying gridview row index number</title><link>http://forums.asp.net/thread/1758844.aspx</link><pubDate>Mon, 18 Jun 2007 04:47:22 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1758844</guid><dc:creator>strazz</dc:creator><author>strazz</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1758844.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=1758844</wfw:commentRss><description>&lt;p&gt;Thanks XIII, that was exactly what I needed, nice and clean.&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: displaying gridview row index number</title><link>http://forums.asp.net/thread/1295963.aspx</link><pubDate>Thu, 25 May 2006 11:33:48 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1295963</guid><dc:creator>XIII</dc:creator><author>XIII</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1295963.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=1295963</wfw:commentRss><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;another way to do it is this one in the Columns section of your GridView control:&lt;/p&gt;&amp;nbsp;&amp;nbsp;&lt;pre class=coloredcode&gt;&amp;lt;&lt;span class=tag&gt;asp:TemplateField&lt;/span&gt;&amp;gt;
    &amp;lt;&lt;span class=tag&gt;ItemTemplate&lt;/span&gt;&amp;gt;
        &lt;span class=dir&gt;&amp;lt;%#&lt;/span&gt; Container.DataItemIndex + 1 &lt;span class=dir&gt;%&amp;gt;&lt;/span&gt;
    &amp;lt;/&lt;span class=tag&gt;ItemTemplate&lt;/span&gt;&amp;gt;
&amp;lt;/&lt;span class=tag&gt;asp:TemplateField&lt;/span&gt;&amp;gt;&lt;/pre&gt;&amp;nbsp;Grz, Kris.</description></item><item><title>Re: displaying gridview row index number</title><link>http://forums.asp.net/thread/1295857.aspx</link><pubDate>Thu, 25 May 2006 09:23:44 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1295857</guid><dc:creator>waters</dc:creator><author>waters</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1295857.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=1295857</wfw:commentRss><description>thanks a lot. it worked:)&lt;br /&gt;</description></item><item><title>Re: displaying gridview row index number</title><link>http://forums.asp.net/thread/1292995.aspx</link><pubDate>Mon, 22 May 2006 18:44:27 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1292995</guid><dc:creator>limno</dc:creator><author>limno</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1292995.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=1292995</wfw:commentRss><description>&lt;p&gt;Another try:&lt;/p&gt;
&lt;p&gt;1. Add this your GridView:&lt;/p&gt;
&lt;p&gt;&amp;lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DataSourceID="SqlDataSource1" OnRowCreated="GridView1_RowCreated1" &amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;lt;Columns&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;asp:TemplateField HeaderText="myRowid"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ItemTemplate&amp;gt;&amp;lt;asp:Label runat="server" /&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/ItemTemplate&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/asp:TemplateField&amp;gt; &lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;&amp;lt;/Columns&amp;gt;&lt;/p&gt;
&lt;p&gt;2. Add this to your code page&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Protected Sub GridView1_RowCreated1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If e.Row.RowType = DataControlRowType.DataRow Then&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Retrieve the Label from the first column.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim myLabel As Label = CType(e.Row.Cells(0).Controls(0), Label)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Set Label text equal to the rowIndex +1 &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myLabel.Text = e.Row.RowIndex.ToString() + 1&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: displaying gridview row index number</title><link>http://forums.asp.net/thread/1292849.aspx</link><pubDate>Mon, 22 May 2006 16:49:27 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1292849</guid><dc:creator>limno</dc:creator><author>limno</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1292849.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=1292849</wfw:commentRss><description>&lt;p&gt;One way to do this by using a new SQL Server 2005 function Row_Number() OVER:&lt;/p&gt;
&lt;p&gt;If you are using SQL Server 2005, you can do something linke this:&lt;/p&gt;
&lt;p&gt;In youe select statement:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;SelectCommand="SELECT Row_Number() OVER(order by id) as rowID, [mycol1], [mycol2], [id] FROM [Table1]"&lt;/p&gt;
&lt;p&gt;In you GridView:&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;lt;asp:BoundField DataField="Rowid" HeaderText="Rowid"&amp;nbsp; ReadOnly="True" SortExpression="Rowid" /&amp;gt;&lt;/p&gt;
&lt;p&gt;You are ready to go.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>displaying gridview row index number</title><link>http://forums.asp.net/thread/1292440.aspx</link><pubDate>Mon, 22 May 2006 11:19:16 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1292440</guid><dc:creator>waters</dc:creator><author>waters</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1292440.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=1292440</wfw:commentRss><description>Hello,&lt;br /&gt;&lt;br /&gt;I have a bit of a problem in displaying row index numbers in a GridView. Something like having first column on every row that displays row number&amp;nbsp; (1, 2, 3 etc). If anyone can help...&lt;br /&gt;&lt;br /&gt;Thanks&lt;br /&gt;</description></item></channel></rss>