User-893317190 posted
Hi Gopi.MCA,
You could use gridview’s ItemTemplate and use a counter in your OnRowDateBound event.
Below is my code.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" />
<asp:BoundField DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName" />
</Columns>
Code behind.
private int count = 1;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (DataBinder.Eval(e.Row.DataItem, "ContactName") != null)
{
if ((DataBinder.Eval(e.Row.DataItem, "ContactName") as string).StartsWith("A"))
{
e.Row.Visible = false;
}
else
{
(e.Row.FindControl("Label1") as Label).Text = count.ToString();
count++;
}
}
}
}
The result.

Best regards,
Ackerly Xu