Row Number in GridView?
-
I've been searching for a while for a way to implement what sounded like a simple customer request. Some of their forms have gridviews on them, and they would simply like a row number in each row. I could change the stored procedure around a bit to generate a row number column, but it seems like there should be an easier way... I've probably been working too long at this point and should just sleep on it, but if someone could give me a quick pointer it would be appreciated!
-
I've been searching for a while for a way to implement what sounded like a simple customer request. Some of their forms have gridviews on them, and they would simply like a row number in each row. I could change the stored procedure around a bit to generate a row number column, but it seems like there should be an easier way... I've probably been working too long at this point and should just sleep on it, but if someone could give me a quick pointer it would be appreciated!
-
Hi Mark, The RowIndex[^] property will give you the row number of each GridViewRow, and this is the zero-based value:
asp:TemplateField
<ItemTemplate>
<%# ((GridViewRow)Container).RowIndex%>
</ItemTemplate>
</asp:TemplateField>minhpc_bk wrote:
The RowIndex[^] property will give you the row number of each GridViewRow, and this is the zero-based value:
Header and footer need to be taken into accout too (if 2.0).....
if (gv.RowIndex==0) { //we have a header row } elseif (gv.RowIndex==1) { //footer } else { //"proper" row } "Now I guess I'll sit back and watch people misinterpret what I just said......" Christian Graus At The Soapbox
-
minhpc_bk wrote:
The RowIndex[^] property will give you the row number of each GridViewRow, and this is the zero-based value:
Header and footer need to be taken into accout too (if 2.0).....
if (gv.RowIndex==0) { //we have a header row } elseif (gv.RowIndex==1) { //footer } else { //"proper" row } "Now I guess I'll sit back and watch people misinterpret what I just said......" Christian Graus At The Soapbox