change Container.DataItemIndex

How can a change the idex number??
I want it to show for every other row So     1 Row shows number
                                                                      2nd row doesn't show number
                                                                       3rd row shows number 2


Any ideas please??

<%# Container.DataItemIndex + 1 %>
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


You're definitely on the right track. You may not be aware of the AlternatingItemTemplate feature which allows you to do things differently every other row. Using that in combination with your approach will get you your desired results.

Like so...

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FormGrid.aspx.cs" Inherits="WebTestBed.FormGrid" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
	<title>Untitled Page</title>
	<form id="form1" runat="server">
		<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSourceExpertsExchange">
						<asp:Label runat="server" Text="<%# Container.DataItemIndex / 2 + 1 %>"></asp:Label>
						<asp:Label ID="Label1" runat="server" Text="No Index Every Other Row"></asp:Label>
				<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True"
					SortExpression="Id" />
				<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
		<asp:SqlDataSource ID="SqlDataSourceExpertsExchange" runat="server" ConnectionString="<%$ ConnectionStrings:ExpertsExchangeConnectionString %>"
			SelectCommand="SELECT [Id], [Name] FROM [GridTable]"></asp:SqlDataSource>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sorry, obviously replace the data connection with your own. I just had to wire something up to ensure the "row count" displayed how you described.
You can use alternatingTemplate like this:
<%# Container.DataItemIndex + 1 %>
           //show or don't show

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.