根据GridView72变的方法,对表格的第一列进行序号重新改写,就是按顺序,1,2,3,4,
代码如下:    protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ////鼠标经过时,行背景色变 
            //e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
            ////鼠标移出时,行背景色变 
            //e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");            ////当有编辑列时,避免出错,要加的RowState判断 
            //if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
            //{
            //    ((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')");
            //}        }
        if (e.Row.RowIndex != -1)
        {
            int id = e.Row.RowIndex + 1;
            e.Row.Cells[0].Text = id.ToString();
        }
    }使用也正常,完全符合要求。
但是我有个页面上使用了三个GridView,就不行了,第一列全部为空白,什么也没有,
反复试了好多回,都没有用。
大家能告诉我是怎么回事吗?多谢!

解决方案 »

  1.   

    应该是自动编号了
      protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
             if (e.Row.RowType == DataControlRowType.DataRow)
             {
                 e.Row.Cells[0].Text = (e.Row.DataItemIndex + 1).ToString();
             }
        }
      

  2.   

    你这三个GridView是不是用了同一个gridView_RowDataBound事件呢?检查一下
      

  3.   

    三个GridView中没有一个是好用的?
      

  4.   

    开始是用不同的RowDataBound,后来搞成同一个RowDataBound,都不行,都不能显示出来,用在其他 的地方都是好好的。
      

  5.   

    是的。三个一个都不行,反复检查,跟别的页面的写法都是一样的,
    为什么就这个不行,
    吧cells【0】该成cells【1】则第二列全部为空白,
    调试的时候,id是有值的为1,2,。。
      

  6.   

    什么意思,每个Gridview都对应着一个相应的RowDataBound的事件,不能共用一个,lz明白?
      

  7.   

    在你的gridview的Columns标记对里加上下面代码<asp:TemplateField HeaderText="" ItemStyle-Width="10px">
        <ItemTemplate>
             <%#Container.DataItemIndex +1 %>
        </ItemTemplate>
    </asp:TemplateField>后台不用去写行号了
      

  8.   

    好的,我去试试看,DataItemIndex是什么,能赐教一下吗?