如果是加上编号,可以在RowDataBound时候添加rowindex,也可以在aspx页面做处理,也可以在选择数据的时候,加上indentity(int,1,1) as rowindex 做编号列(select into)。如果是排序的话,没有在数据选择的时候做,也可以用gridview的sort来做。

解决方案 »

  1.   

     <asp:TemplateField HeaderText="序号">
                                        <ItemTemplate>
                                             <%# (Container.DataItemIndex + 1).ToString()%>
                                        </ItemTemplate>
                                        <ItemStyle HorizontalAlign="Center" Width="30px" />
                                    </asp:TemplateField>
      

  2.   

    为 Gridview 增加新列,如下:
    <asp:BoundField  HeaderText="序号">
                         </asp:BoundField>在RowDataBound 事件中编写代码:
     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
             if (e.Row.RowIndex > -1)
            {
              
             e.Row.Cells[0].Text = Convert.ToString(e.Row.RowIndex + 1);
            }
               
      }
      

  3.   

    GridView属性设置AllowSorting为TRUE
    创建Sorting事件
    在Sorting里写上排序,无须安排编号。
      

  4.   

    你在SQl语句里就写上Order by 那个数字列的在字段名称 DESC或者ASC   要不你就将GridView属性设置AllowSorting为TRUE 在collction里面设置绑定字段 创建Sorting事件