gridview可以增加一列,你加载时,在RowDataBound事件中,给这个列顺序赋值

解决方案 »

  1.   

    https://social.msdn.microsoft.com/Forums/windowsdesktop/zh-CN/6cfd5f23-8329-4dcb-ac92-171a66c5e107/cnet
      

  2.   


    数据库中根本没有公开给你的固定的顺序,你查询时应该写 order by 语句来执行顺序,这才会有“第几天记录”的概念。
      

  3.   

    //****声明一个变量
    private int intRow=0; //****构造一个自增变量函数
    public int AutoRowNumber()
     {
       return intRow++;
     }
     //*****前台邦定,datagive模版列中邦定即可//****例如:
      <asp:GridView ID=GView runat=server AutoGenerateColumns="False" OnRowCommand="GView_RowCommand" OnRowEditing="GView_RowEditing" OnRowCancelingEdit="GView_RowCancelingEdit" OnRowDataBound="GView_RowDataBound" AllowPaging="True" AllowSorting="True"  OnPageIndexChanging="GView_PageIndexChanging" PageSize="2">
              <Columns>
                   <asp:TemplateField>
                   <ItemTemplate>
                    <%=AutoRowNumber()%>
                    </ItemTemplate>
                 </asp:TemplateField>
             </columns>
     <asp:datagive/> 
      

  4.   

    利用GridView查看数据表中的商品ID值,判断数据库中为第几条记录示例
    //GridView设置显示ID值
    <asp:GridView ID="gvGoodsInfo" runat="server" CellPadding="4" 
                    ForeColor="#333333" GridLines="None" Font-Size="9pt" 
                    AutoGenerateColumns="False" AllowPaging="True" PageSize="8" 
                    OnPageIndexChanging="gvGoodsInfo_PageIndexChanging" Width="450px">
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <EditRowStyle BackColor="#999999" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                    <PagerStyle BackColor="#CBCF7A" ForeColor="Black" HorizontalAlign="Right" />
                    <HeaderStyle BackColor="#CBCF7A" Font-Bold="True" ForeColor="White" />
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                    <Columns>
                        <asp:BoundField DataField="PicId" HeaderText="商品ID" />
                        <asp:BoundField DataField="PicType" HeaderText="所属类别" />
                        <asp:BoundField DataField="GoodsStock" HeaderText="库存量" />
                        <asp:BoundField DataField="PicName" HeaderText="商品名称" />
                        <asp:HyperLinkField HeaderText="详细信息" Text="详细信息" DataNavigateUrlFields="PicId" 
                            DataNavigateUrlFormatString="EditGInfo.aspx?GoodsID={0}" Target="mainframe" 
                            NavigateUrl="~/MemberManage/EditGInfo.aspx" >
                            <ControlStyle Font-Underline="False" ForeColor="Black" />
                            <ItemStyle Font-Underline="False" ForeColor="Black" />
                            <HeaderStyle Font-Underline="False" ForeColor="Black" />
                        </asp:HyperLinkField>
                    </Columns>
                </asp:GridView>
    //绑定数据显示
    SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
        protected void Page_Load(object sender, EventArgs e)
        {
            string sqlstr = "select * from tbPicture";               //创建执行查询操作的SQL语句
            sqlcon.Open();//打开数据库连接
            SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);//创建数据阅读器
            DataSet myds = new DataSet();                           //创建数据集
            myda.Fill(myds);                                        //填充数据集
            gvGoodsInfo.DataSource = myds;                          //设定数据源
            gvGoodsInfo.DataBind();                                 //绑定数据
            sqlcon.Close();                                         //关闭数据库连接
        }
      

  5.   

    gridview是翻页的,我用的AspNetPager控件,每翻一次页就会从0开始算,所以不能判断查询到的某条记录在第几页,只能判断查询到的记录在第几行。
      

  6.   

    http://bbs.csdn.net/topics/70277558
    可以为原来的数据库新添加一列,列值为自加1,到时候查询值小于等于该值一共有多少行,那此行就是第几行。