2011-06-20 60 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>