You can also set the Serial No in html file as given below.
Solution : 1
<asp:TemplateField HeaderText="S.No">
<ItemTemplate>
<asp:Label ID="lblSnNo" runat="Server" Text='<%# Container.ItemIndex + 1 %>' />
</ItemTemplate>
</asp:TemplateField>
Solution :2
Use itemTemplate and then in rowdatebound event put the row index + 1 in that template....for example
<asp:TemplateField HeaderText="Edit/Delete">
<ItemTemplate>
<asp:Label ID="lblSnNo" runat="Server" />
</ItemTemplate>
</asp:TemplateField>
and in code behind
Private Sub gvCommon_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvCommon.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
CType(e.Row.FindControl("lblSnNo"), Label).Text = e.Row.RowIndex + 1
End If
End Sub
Solution : 1
<asp:TemplateField HeaderText="S.No">
<ItemTemplate>
<asp:Label ID="lblSnNo" runat="Server" Text='<%# Container.ItemIndex + 1 %>' />
</ItemTemplate>
</asp:TemplateField>
Solution :2
Use itemTemplate and then in rowdatebound event put the row index + 1 in that template....for example
<asp:TemplateField HeaderText="Edit/Delete">
<ItemTemplate>
<asp:Label ID="lblSnNo" runat="Server" />
</ItemTemplate>
</asp:TemplateField>
and in code behind
Private Sub gvCommon_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvCommon.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
CType(e.Row.FindControl("lblSnNo"), Label).Text = e.Row.RowIndex + 1
End If
End Sub
Comments
Post a Comment