1

我在下面的页面上有一个复选框列表。

   <asp:CheckBoxList runat="server" ID="lstFeatures" RepeatDirection="Vertical"></asp:CheckBoxList>  

后端代码看起来像这样。

    private void MakeRegionCheckboxes(ReportRegion region, int margin)
    {
        foreach (ReportRegion subregion in region.childRegions)
        {
            ListItem item = new ListItem();
            item.Text = subregion.Name;
            item.Value = subregion.Name;
            item.Selected = subregion.DefaultSelection;
            item.Attributes.Add("style", "margin-left:" + margin.ToString() + "px");
            lstFeatures.Items.Add(item);

            MakeRegionCheckboxes(subregion, margin + 30);
        }
    }

当它在一个空白项目上运行时,它会很好地缩进“子区域”,因为 style:margin-left:30px 在跨度中呈现,如您所见。

<td>
  <span style="margin-left:30px">
  <input id="lstFeatures_1" type="checkbox" checked="checked" name="lstFeatures$1">
  <label for="lstFeatures_1">Member Information</label>
  </span>
</td>

但是,当我在主项目中运行相同的代码时,它不会呈现跨度,因此没有设置边距。我得到的只有这个。

<td>
   <input id="ctl00_pg_BuildReport_lstFeatures_1" type="checkbox" checked="checked" name="ctl00$pg$BuildReport$lstFeatures$1">
   <label for="ctl00_pg_BuildReport_lstFeatures_1">Member Information</label>
</td>

这两个项目(3.5)的框架相同,唯一的区别是主项目有一个母版页,也许还有一些额外的面板,但我只是想知道什么会阻止渲染的跨度?任何帮助都会很有用。谢谢!

4

1 回答 1

1

试试这个,看看有没有效果:

item.Attributes.CssStyle.Add("margin-left", String.Format("{0}px", margin));
于 2012-10-01T02:14:25.303 回答