2011-11-07 38 views

回答

1

在GridView上設置SelectedRowStyle-BackColor屬性。

0

你可以使用這個屬性來更改行的顏色...

//這個添加到代碼隱藏....

protected void MyGridView_RowCreated(object sender, GridViewRowEventArgs e) 
{  
    string rowID = String.Empty;  
    if (e.Row.RowType == DataControlRowType.DataRow)  
    {  
     rowID = "<strong class="highlight"><vb_highlight>row</strong></vb_highlight>"+e.Row.RowIndex;  
     e.Row.Attributes.Add("id","<strong class="highlight"><vb_highlight>row</strong></vb_highlight>"+e.Row.RowIndex); 

     e.Row.Attributes.Add("onclick","ChangeRowColor(" +"'" + rowID + "'" + ")"); 

    }  
} 

//一下添加到網頁設計師....

<script language ="javascript" type="text/javascript"> 
    document.body.style.cursor = 'pointer';  
    var oldColor = ''; 

    function ChangeRowColor(rowID)  
    { 

     var <strong class="highlight">color</strong> = document.getElementById(rowID).style.backgroundColor;  
     if(<strong class="highlight">color</strong> != 'yellow')  
     oldColor = <strong class="highlight">color</strong>;  
     if(<strong class="highlight">color</strong> == 'yellow')  
       document.getElementById(rowID).style.backgroundColor = oldColor; 
     else 
      document.getElementById(rowID).style.backgroundColor = 'yellow';  
     }  
    </script> 

我希望它會幫助你..

+0

感謝errorstacks,烏拉圭回合help.What是。我在寫代碼的C#.net.I我收到SYN (Add;)。onclick是gridview中存在的按鈕事件。寫在

相關問題