怎么样是gridview 前面10条数据具有背景色, 页面上显示的是25条数据?
这个该怎么实现?

解决方案 »

  1.   

    $('tr :eq(9)').prev().css('background-color', 'red');
      

  2.   

    <%# Container.DataItemIndex<10 ? "" : "" %>
      

  3.   

    可以在RowDataBound事件中设定行的样式。
      

  4.   

    private void DataGrid1_PreRender(object sender, System.EventArgs e) {
    if(this.DataGrid1.Items.Count >=10){
    for(int i=0;i<=10;i++){
    this.DataGrid1.Items[i].BackColor = System.Drawing.Color.Red;
    }
    }
    }
      

  5.   

     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
    if(e.Row.RowIndex<=10)
    {
    e.Row.BackColor = Color.Red;
    }
    }
    }
      

  6.   

    Insus.NET习惯是写在OnRowCreated事件,而非onRowDataBound事件:
    http://www.cnblogs.com/insus/articles/2060705.html
      

  7.   

            protected void Grid_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    if (e.Row.RowIndex < 10)
                        e.Row.Attributes.Add("style", "background:#000");
                }
            }
      

  8.   

    1.
    $(function(){
       $('tr gt(9)').addClass('红色背景样式名称');
    })2.
    可以利用这个Container.DataItemIndex
    <tr <%# Container.DataItemIndex < 10 ? "style=\'backgournd-color:red\'" : "" %> >
       ....
    </tr>
      

  9.   

    $('tr:gt(9)').addClass('红色背景样式名称') --- 忘记下 ":" 了
      

  10.   

    在rowcreate事件里写 
    if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.RowIndex < 10) 
                {
                    e.Row.BackColor = Color.Red; 
                }
            }