Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To add a Serial Number as the First Column in a GridView

I have a Grid View . It has two bound columns. I need to have a Serial Number column as the first column.

How can i do that ? Thanks in Advance

like image 947
Ananth Avatar asked Jan 22 '11 08:01

Ananth


2 Answers

<asp:TemplateField HeaderText="S No">
    <ItemTemplate>
        <%# Container.DataItemIndex + 1 %>
    </ItemTemplate>
    <ItemStyle Width="2%" />
</asp:TemplateField>
like image 66
R.Ilayaraja Avatar answered Sep 18 '22 14:09

R.Ilayaraja


Create a datatable with two columns use a first column as autoincrement as true and AutoIncrementStep=1 like

DataTable _test = new DataTable();
DataColumn c = new DataColumn("sno", typeof(int));
c.AutoIncrement = true;
c.AutoIncrementSeed = 1;
c.AutoIncrementStep = 1;
_test.Columns.Add(c);
_test.Columns.Add("description");
gvlisting.DataSource = _test;
like image 40
Navaneethan Avatar answered Sep 19 '22 14:09

Navaneethan