Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
How to get Grid View Row number in Asp.net.....
Posted

Container.DataItemIndex would help you.
ASP.NET
<columns>
    <asp:templatefield headertext="Row Number" itemstyle-width="100" xmlns:asp="#unknown">
        <itemtemplate>
            <asp:label id="lblRowNumber" text="<%# Container.DataItemIndex + 1 %>" runat="server" />
        </itemtemplate>
    </asp:templatefield>
    <asp:boundfield datafield="Name" headertext="Name" itemstyle-width="150" xmlns:asp="#unknown" />
    <asp:boundfield datafield="Country" headertext="Country" itemstyle-width="150" xmlns:asp="#unknown" />
</columns>

Read this article here[^]

-KR
 
Share this answer
 
Comments
Member 11130277 17-Oct-15 7:26am    
not working
Krunal Rohit 18-Oct-15 2:31am    
Did you refer the article ?

-KR
protected void gridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int index = e.Row.RowIndex;
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900