在我datagrid里有一列值
我現在想值等于1的時候顯示黑色,否則就顯示紅色
怎么做?

解决方案 »

  1.   

    <html><head>
    <meta http-equiv="Content-Language" content="zh-cn">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>新建网页 1</title>
    </head><body onload="changeColor()">
    <script>
    var bIgnoreHeader = false; //是否忽略第一行 ,ingore=true
    var bIgnoreFooter = false; //是否忽略最后一行,ingore=true
    function changeColor()
    {
    var tab = document.getElementById("DataGrid1")
    var rowCount= tab.rows.length;
    for(var i = 0 ;i<rowCount;i++)
    {
    //忽略第一行
    if(i==0)
    if(bIgnoreHeader) continue;
    //忽略最后一行
    if(i==(rowCount-1))
    if(bIgnoreFooter) continue;
    //第n行就是 cell[n-1]
    if(tab.rows[i].cells[0].innerText=="1")
    {
    tab.rows[i].style.backgroundColor="#e4e4de";
    }
    }
    }

    </script>
    <table border="1" width="100%" id="DataGrid1">
    <tr>
    <td>2</td>
    <td> </td>
    </tr>
    <tr>
    <td>1</td>
    <td> </td>
    </tr>
    <tr>
    <td>1</td>
    <td> </td>
    </tr>
    <tr>
    <td>3</td>
    <td> </td>
    </tr>
    <tr>
    <td>1</td>
    <td> </td>
    </tr>
    </table>
    </body></html>
      

  2.   

    datagrid1_itemdatabind()
    {
    if(e.item.itemtype==listitemtype.item||e.item.itemtype==listitemtype.alteritem)
    {
    if(e.item.cells[0].text=="1")
    e.item.backcolor=color.Red;//类似这样的写法
    }
    }