如何自动生成序列号在数据网格中 [英] how to autogenerate serial no. in datagrid

查看:114
本文介绍了如何自动生成序列号在数据网格中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自动生成序列号.在数据网格中
我正在使用此代码

Hi, i want to auto generate serial no . in data grid
I am using this code

<asp:DataGrid ID="dgdefaulertlist" runat="server" Width="85%" AutoGenerateColumns="false"
                   BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal" AllowPaging="True" PageSize="40"  Height="10%"  OnPageIndexChanged="dgdefaulertlist_PageIndexChanged" AllowSorting="True" >
                   <Columns>
                       <asp:TemplateColumn HeaderText = "Serial No.">
                       <ItemTemplate>
                       <asp:Label ID = "lblserial" Text ='<%# Container.DataItemIndex + 1%>' runat= "server"></asp:Label>
                       </ItemTemplate>
                       </asp:TemplateColumn>
                    <asp:BoundColumn HeaderText="Date" DataField="startdate"></asp:BoundColumn>
                    <asp:BoundColumn HeaderText="Employee Name" DataField="employeename"></asp:BoundColumn>
                   </Columns>
                   <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
                   <SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
                   <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" Mode="NumericPages" />
                   <ItemStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
                   <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
                   <AlternatingItemStyle BackColor="#F7F7F7" />
               </asp:DataGrid>



它给出了错误
``System.Web.UI.WebControls.DataGridItem''不包含``DataItemIndex''的定义

在此先感谢



it gives error
''System.Web.UI.WebControls.DataGridItem'' does not contain a definition for ''DataItemIndex''

Thanks in Advance

推荐答案

Container.DataItemIndex  does not support gridview

use it <%# Container.ItemIndex+1 %>


这篇关于如何自动生成序列号在数据网格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆