Click here to Skip to main content
15,901,283 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
merhaba
asp.net vb yaptığım projemde SqlDataSource1 ile verileri gridview' de son 10 kayıt ID sıralaması ile gösteriyorum.

GridView1.Sort("ID", SortDirection.Descending)
(1105,1104,1103,1102,1101,1100.....)

Buraya kadar sorun yok.
Ben tekrardan sol tarafa manuel bir ID colunms oluşturarak sabit kalacak şekilde (10,9,8,7,6,5,4,3,2,1) satır oluşturmak istiyorum.

Bu konu hakkında yardımcı olabilir misiniz.

UPDATE (English translated):
Hi
In my asp.net etc. project, I show the data with SqlDataSource1 in gridview with the last 10 record ID order.

GridView1.Sort ("ID", SortDirection.Descending)
(1105,1104,1103,1102,1101,1100 .....)

So far there is no problem.
I want to create a manual ID colunms on the left side again and create a row (10,9,8,7,6,5,4,3,2,1) that will remain constant.

Can you help with this topic.

What I have tried:

For i = 0 To GridView1.Rows.Count - 1
GridView1.Rows(i).Cells(0).Value = i+1
Next
Posted
Updated 10-Sep-20 3:08am
v2

It is really unclear what you are trying to achieve so here are a few suggestions

1. IF you are trying to add a row number column to the Gridview then it is as simple as including the following snippet in your gridview definition
ASP.NET
<asp:TemplateField HeaderText="ID" >
     <ItemTemplate>
     <%# Container.DataItemIndex + 1 %>
     </ItemTemplate>
</asp:TemplateField>
You may have to change the calculation if you want the row number reversed. This suggestion is all over the Internet, which you can find by using the search term
Search for:
asp net gridview label row number
Note that this will always show the GridView row number

2. IF you are trying to assign a row number to the SQL results that you are binding to, then you can use the ROW_NUMBER (Transact-SQL) - SQL Server | Microsoft Docs[^] function. Note this will always show the row number as returned even if you sort the GridView
 
Share this answer
 
merhaba
konu hakkında yardımcı olduğunuz için teşekkür ederim.
 
Share this answer
 
Comments
OriginalGriff 25-Sep-20 4:25am    
Don't post comments as solutions: the original poster doesn't get any notification.
Us ethe "Have a Question or Comment?" widget instead, and they will get an email.

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