2015-11-24 37 views
1

我設置了3個重複列,我想爲每個重複列使用不同的背景顏色,如果您對我如何實現這一點有任何想法,請分享。如何爲每個重複列的RadioButtonList設置不同的背景顏色

下面是我RadioButtonList代碼

<asp:RadioButtonList ID="rblTimeSlot" runat="server" RepeatColumns="3" RepeatLayout="Table" AutoPostBack="False" CellPadding="10" CellSpacing="2" Font-Bold="False"></asp:RadioButtonList> 

項目列表從數據庫加載另一事件。

在此先感謝。

回答

1

使用CSS nth-child(> = IE9):

#rblTimeSlot tr:nth-child(even) 
{ 
    background-color:aqua; 
} 

或者jQuery的:

$("#rblTimeSlot tr:even").css("background-color","aqua"); 

如果你想要做同樣爲列,使用此略有改變CSS:

#rblTimeSlot tr > td:nth-child(even) 
{ 
    background-color:aqua; 
} 

或jquery:

$("#rblTimeSlot tr>td:even").css("background-color","aqua"); 
+0

它的工作原理,但對我行僅怎樣才能使之成爲 –

+0

的偉大工程列,謝謝。 –

0

你可以把代碼寫在你的XX.aspx.cx文件是這樣的:

string[] color = { "red", "yellow","blue" }; 
for (int i = 0; i < rblTimeSlot.Items.Count; i++) 
{ 
    int j = i % color.lenght; 
    rblTimeSlot.Items[i].Attributes.Add("style", "color: " + color[j]+ ";"); 

} 
+0

沒有特定數量的時間片,所以我需要指定很長的顏色數組,但答案很有用,可以在其他地方使用此:) –

相關問題