2011-06-20 54 views

回答

3

您可以在GridView中使用Container.DataItemIndex。它将显示上述序列号。

<asp:TemplateField HeaderText="SNo."> 
    <itemtemplate> 
      <%#Container.DataItemIndex + 1 %>              
    </itemtemplate> 
</asp:TemplateField> 
0

我建议将此数据添加到您用来绑定到GridView的源。因此,如果您有绑定到GridView的ICollection<Product>,请将序列号添加到产品类。

或者,您可以将ICollection<Product>转换为Dictionary<int, Product>,并将该密钥绑定到序列号列。

很难知道如果不知道您的数据是如何得到标记的话,会很适合。

-1

使用谷歌搜索serial number column gridview会给你数百万的结果,讨论同样的事情。阅读文章/教程/讨论并实施它。 请问Google之前请做Google。

+1

这是事实,但最终谷歌将指向喜欢这篇文章的结果,所以我们有责任回答这个问题。 – Digbyswift

+0

这是如何添加任何值作为答案 – V4Vendetta

+0

讨论数千次讨论过的同样的事情有什么意义。恕我直言,如果做一个简单的谷歌搜索可以帮助你找到答案,那么这样做是值得的,而不是花时间写一个问题,等待答复。 –

0

将此模板字段添加到标签列中。你会得到AutoGenerate SNo。

更多信息请参考以下链接

How to create autogenerate serial number column in GridView

<asp:GridView ID="GridEmployee" runat="server" AutoGenerateColumns="false" 
     CellPadding="5" Style="background-color: rgb(241, 241, 241); width: 50%;"> 
        <Columns> 
         <asp:TemplateField HeaderText="S.No"> 
          <ItemTemplate> 
           <%#Container.DataItemIndex+1 %> 
          </ItemTemplate> 
         </asp:TemplateField> 
        </Columns> 
       </asp:GridView> 

我希望这可以帮助你。由于

0

下面是简单的方法...

<ItemTemplate>     
    <%#Container.ItemIndex + 1 %> 
</ItemTemplate>