我正在尝试从标签中删除字词,直到它低于指定的允许宽度。然而,当我循环遍历转发器项时,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;
}
}