我正在尝试从标签中删除单词,直到它低于指定的允许宽度。但是,当我遍历中继器项目时,Width = 0 和 Text 属性始终为空。
我已经尝试将我的代码移动到 OnItemDataBound
private void loadData()
{
Activities activities = new Activities();
var acts = activities.getNextActivities(3);
if (acts.Count > 0)
{
rptActivities.DataSource = acts;
rptActivities.DataBind();
foreach (RepeaterItem item in rptActivities.Items)
{
Label lblActName = (Label)item.FindControl("lblActName");
Unit width = lblActName.Width;
while (width.Value > 310)
{
int pos = lblActName.Text.LastIndexOf(" ") < 0 ? 0 : lblActName.Text.LastIndexOf(" ");
lblActName.Text = lblActName.Text.Substring(0, pos);
width = lblActName.Width;
}
}
}
else
{
pnlItems.Visible = false;
pnlNoItems.Visible = true;
}
}