我們正試圖改變直放站的DropDownList的背景顏色爲灰白單選按鈕列表selectedItem屬性是新的。有條件地改變Repeater DropDownList的背景顏色?
否則,保持背景爲白色。
下面的代碼保存在後臺到格雷RadioButtonList的selectedItem屬性是否是新的或使用。
我錯過了什麼?
// CSS
<style>
.disabledcss
{
background-color: #F9F9F9;
color: blue;
border: 1px solid gray;
color: Gray;
}
</style>
<style>
.enabledcss
{
background-color: #fff;
color: blue;
border: 1px solid white;
color: Gray;
}
</style>
//標記:
<tr>
<td>
Item Type:<asp:RadioButtonList ID="rblPType" runat="server" ValidationGroup ="stype" RepeatDirection="Horizontal" TextAlign="Right" style="display:inline;" AutoPostBack="true" OnSelectedIndexChanged="rblPurchaseType_SelectedIndexChanged">
<asp:ListItem Text="New" />
<asp:ListItem Text="Used" />
</asp:RadioButtonList><br />
<asp:RequiredFieldValidator style="color:#ff0000;" id="RequiredFieldValidator1" ControlToValidate="rblPurchaseType" ErrorMessage="Please choose New or Used" ValidationGroup ="stype" runat="server" />
</td>
<td></td>
</tr>
<tr>
<td colspan="2">
<asp:Panel ID="uPanel" runat="server" Enabled="false">
STATE: <asp:DropDownList ID="ddlState" cssClass="disabledcss enabledcss" runat="server" AppendDataBoundItems="True">
<asp:ListItem Value="" Selected="True"></asp:ListItem>
</asp:DropDownList>
</div></span></asp:Panel>
</td>
</tr>
C#在ItemDataBound事件
RadioButtonList rbPurchase = e.Item.FindControl("rblPType") as RadioButtonList;
foreach (RepeaterItem ReapterItem in Repeater2.Items)
{
var rblType = (DropDownList)e.Item.FindControl("ddlState");
if (rblType.Enabled == false)
{
rblType.CssClass = "disabledcss";
}
else
{
rblType.CssClass = "enabledcss";
}
}
注:我看到的這個論壇不約三個例子適用於我自己。 謝謝
在您的瀏覽器中的HTML,您的課程是否會來? – Yogesh
爲什麼你同時使用cssClass =「disabledcss enabledcss」?你也可以發送完整的HTML標記嗎? –
@SamanGholami,我最初使用的是disabledcss類,這導致了灰色背景。添加enabledcss類沒有任何區別。無論如何,爲了萬一我可能遺漏了一些東西,我在這裏發佈了它。 完整的CSS是1500行。我發佈了相關的代碼。 – Kenny