小记

项目需求内容列表必须有规则的序号,而数据库中的主键又不是连续的,所以只能人为添加上去。

DataList的编号是从0开始,所以用以下代码:

<asp:Label ID="lblQNum" runat="server" Text='<%# Container.ItemIndex+1 %>' Font-Bold="True"></asp:Label>

GridView也类似,稍微有点点不同,用的是:DataItemIndex

<asp:Label ID="lblSNum" runat="server" Text='<%# Container.DataItemIndex+1 %>'></asp:Label>

如果用到分页:

  <td height="20" align="center" bgcolor="#E1F4EE"> <%#GetIndex( Container.ItemIndex) %></td>

代码:

 //编号
    protected string GetIndex( int index)
    {
        index = (FenYe.CurrentPageIndex - 1) * FenYe.PageSize + index + 1;
      return index.ToString();
    }

posted @ 2008-07-25 18:38  海皮球  阅读(112)  评论(0编辑  收藏  举报