【发布时间】:2017-08-11 23:21:09
【问题描述】:
当 RadioButtonList selectedItem 为 New 时,我们正在尝试将 Repeater DropDownList 的背景颜色更改为灰色。
否则,将背景保持为白色。
无论 RadioButtonList selectedItem 是 New 还是 Used,以下代码都将背景保持为灰色。
我错过了什么?
//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>
ItemDataBound 事件中的 C#
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 上,你的课要来了吗?
-
你为什么同时使用cssClass="disabledcss enabledcss"?您也可以发送完整的 HTML 标记吗?
-
@SamanGholami,我最初使用 disabledcss 类,结果只是灰色背景。添加 enabledcss 类没有任何区别。我还是把它贴在这里,以防万一我遗漏了一些东西。完整的 CSS 长度为 1500 行。我贴了相关代码。
-
发布 ASP 控件的代码,而不是 CSS
-
我做到了。我发布了asp 控件(RadioButtonList 和DropDownList)控件。两者都在中继器内。我还在 ItemDataBound 事件中发布了我正在使用的 C#。