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
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