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
 
Ad

Advertisements


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

Top