方法一:
.aspx代码
<form id="form1" method="post" runat="server">
<font face="宋体">
<asp:textbox id="textbox1"
runat="server"></asp:textbox>
<asp:button id="button1" runat="server"
text="设 置"></asp:button>
<asp:label id="label2" runat="server">动态设置textbox的样式</asp:label>
<asp:label id="label1" runat="server"></asp:label></font>
</form>
.aspx.cs代码
private void button1_click(object sender, system.eventargs e)
{//设置样式
textbox1.style.add("width",textbox1.text.tostring());
label1.text="宽度"+textbox1.style["width"].tostring();
}
方法二:
.aspx代码
<form id="form1" method="post" runat="server">
<asp:label id="label1" runat="server">动态设置服务器控件的样式</asp:label>
<asp:button id="button1" runat="server"
text="设 置"></asp:button>
<asp:textbox id="textbox1" runat="server"></asp:textbox>
</form>
.aspx.cs代码
private void button1_click(object sender, system.eventargs e)
{//设置样式
style style=new style();
style.bordercolor=color.black;
style.borderstyle=borderstyle.inset;
style.borderwidth=new unit(1);
textbox1.applystyle(style);
}
新闻热点
疑难解答
图片精选