problem when adding values in label of gridview

L

Luc

Hi,

i have a gridview connected to a sqldatasource.
Now i want to add a label on each row with value starting at 1 then 2, 3 etc
....
So i added a template containing a label.

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
DataKeyNames="id" >
<Columns>
<asp:CommandField ShowSelectButton="true" />
<asp:TemplateField>
<ItemTemplate>
<asp:Label id="Label1" runat="server""></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="link" SortExpression="link" />
<asp:BoundField DataField="id" HeaderText="id" readonly="true"/>
</Columns>
....
</asp:GridView>

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound
Dim amountrec = GridView1.Rows.Count
dim i as integer

If e.Row.RowType = DataControlRowType.DataRow Then
Dim lb As Label = e.Row.FindControl("Label1")
for i=1 to amountrec
lb.text=i
next
End If
end sub

My problem: the first row is ignored. The '1' comes into the second row etc
....
How can i solve this?
Thanks
Luc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top