c# - 如何在运行时从代码隐藏更改 CSS 键的值?

标签 c# asp.net css

我有一个相当简单的页面,它查询 Web 服务以从 SQL 服务器中提取数据,返回一个大小不一的通用列表。我想做的是在运行时调整 div 的高度,在 foreach 循环的每次迭代中向现有 CSS 键添加一定数量的像素,以便投影列表不会溢出容器 div。

我用来将列表放在页面上的代码如下:

int total = 0;
lstUsageServices.Text = string.Empty;
lstUsageRequests.Text = string.Empty;
if (txtAccount.Text != string.Empty)
{
soapClient = new UsageService.ServiceSoapClient();
foreach (UsageClient.UsageService.Usage current in soapClient.GetUsage(txtAccount.Text, startPicker.SelectedDate, endPicker.SelectedDate))
{
lstUsageServices.Text += current.Service + "<br />";
lstUsageRequests.Text += current.Requests.ToString() + "<br />";
total += current.Requests;                        
}
lstUsageServices.Text += "<strong>Total</strong>";
lstUsageRequests.Text += "<strong>" + total.ToString() + "</strong>";

我想做的是在 foreach 中添加一行来引用一个 div:

<div class="main" runat="server" id="mainDiv">

并增加CSS“height:Xpx;”每次迭代。

希望有人能帮忙,看来这应该不是什么难事!提前致谢:)

最佳答案

一个简单的方法可以是

mainDiv.Attributes.CssStyle.Add("height", "Xpx");

关于c# - 如何在运行时从代码隐藏更改 CSS 键的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13044980/

相关文章:

asp.net - 数据列表中的超链接

javascript - 在移动设备中,空白 :nowrap; overflow:hidden; text-overflow:ellipsis; kinda do not work

html - CSS Font Awesome 图标在 IE 10 中可点击

c# - asp.net c# 中的 SQL 错误

javascript - 将多个字符串值作为参数从服务器端传递给 JavaScript 函数

c# - 从结构为 "key=value"的字符串中解析值

html - 无法获得证明内容 : space-between to work in Bootstrap framework

c# - 在 Visual C# 中移动菜单

c# - 如何创建可枚举/类字符串或 int 并序列化?

c# - ASP.NET : the connection is closed