gpt4 book ai didi

c# - 我需要更改 asp :buttons that are in a ListView from code behind

转载 作者:太空宇宙 更新时间:2023-11-04 15:01:05 27 4
gpt4 key购买 nike

我在 ListView 中有一些按钮,我需要通过代码隐藏更改它们的 CSS 属性,以便可以通过函数动态更改颜色。

我收到以下错误:

**Error 6 The name 'SubDomainButton' does not exist in the current context.**

我很高兴能够编辑当前分配给按钮的 CSS 类或引用 ListView 内的按钮。

我想做类似...

SubDomainButton.Style.Add("border-color", (string)    (Session["BorderFontColor"]));
SubDomainButton.Style.Add("color", (string)(Session["BorderFontColor"]));
SubDomainButton.Style.Add("background-color", (string)(Session["BackgroundColor"]));

HTML 段:

<asp:ListView ID="SubDomainListView" runat="server" DataKeyNames="ID" DataSourceID="SubDomainSqlDataSource"
EnableModelValidation="True" OnItemCommand="SubDomainListView_ItemCommand">

<itemtemplate>
<asp:Button ID="SubDomainButton" runat="server" Text='<%# Eval("SubDomain") %>' CommandText="click" CommandName="Select"
CommandArgument='<%# Eval("ID")%>' UseSubmitBehavior="False" CssClass="button" />
</itemtemplate>
<selecteditemtemplate>
<asp:Button ID="Button2" runat="server" Text='<%# Eval("SubDomain") %>' CommandText="click" CommandName="Select"
CommandArgument='<%# Eval("ID")%>' UseSubmitBehavior="False" CssClass="buttoninact" Enabled="False" />
</selecteditemtemplate>
<layouttemplate>
<div id="itemPlaceholder" runat="server">
</div>
</layouttemplate>
</asp:ListView>

CSS: /* 按钮样式 */

.button {
-webkit-box-shadow: rgba(0,0,0,0.0.1) 0 1px 0 0;
-moz-box-shadow: rgba(0,0,0,0.0.1) 0 1px 0 0;
box-shadow: rgba(0,0,0,0.0.1) 0 1px 0 0;
border: 1px solid;
font-family: Lucida Grande,Tahoma,Verdana,Arial,sans-serif;
font-size: 12px;
font-weight: 700;
padding: 2px 6px;
height: 28px;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
text-decoration: underline;
}

/*Hover Styles*/
.button:hover {
-webkit-box-shadow: rgba(0,0,0,0.0.1) 0 1px 0 0;
-moz-box-shadow: rgba(0,0,0,0.0.1) 0 1px 0 0;
box-shadow: rgba(0,0,0,0.0.1) 0 1px 0 0;
border: 1px solid;
font-family: Lucida Grande,Tahoma,Verdana,Arial,sans-serif;
font-size: 12px;
font-weight: 700;
padding: 2px 6px;
height: 28px;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
text-decoration: none;
}

.buttoninact {
-webkit-box-shadow: rgba(0,0,0,0.0.1) 0 1px 0 0;
-moz-box-shadow: rgba(0,0,0,0.0.1) 0 1px 0 0;
box-shadow: rgba(0,0,0,0.0.1) 0 1px 0 0;
border: 1px solid;
font-family: Lucida Grande,Tahoma,Verdana,Arial,sans-serif;
font-size: 12px;
font-weight: 700;
padding: 2px 6px;
height: 28px;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
text-decoration: none;
}

最佳答案

您可以通过添加内联 CSS 样式来实现:

<itemtemplate>
<asp:Button ID="SubDomainButton" runat="server" Text='<%# Eval("SubDomain") %>' CommandText="click" CommandName="Select" CommandArgument='<%# Eval("ID")%>' UseSubmitBehavior="False" CssClass="button"
style='<%# String.Format("border-color: {0}; color: {1}; background-color: {2};",(string)Session["BorderFontColor"],(string)Session["BorderFontColor"],(string)Session["BorderFontColor"]) %>' />
</itemtemplate>

关于c# - 我需要更改 asp :buttons that are in a ListView from code behind,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16403673/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com