I have 1 data gridview. in that first is ID column . for that i assign a auto index number with sql server (isidentiyt). the next colomn is response id, for this column also i want autonumber id like 1,2,3,4..... . i see we cant assign to index identity with sql server for one table. can we generate tis id for gridview column with code.?
please help!

I have 1 data gridview. in that first is ID column . for that i assign a auto index number with sql server (isidentiyt). the next colomn is response id, for this column also i want autonumber id like 1,2,3,4..... . i see we cant assign to index identity with sql server for one table. can we generate tis id for gridview column with code.?
please help!

Add a column at runtime

TemplateField col=new TemplateField();
        col.HeaderText="Response ID";
        GridView1.Columns.Add(col);
        //bind the data
        int count = GridView1.Rows.Count;
        for (int i = 0; i < count; i++) {
            GridView1.Rows[i].Cells[0].Text = (i + 1).ToString();
        }
<asp:TemplateField>
    <ItemTemplate>
        <%# Container.DataItemIndex + 1 %>
    </ItemTemplate>
</asp:TemplateField>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.