添加控件后如何随机化控件
我有三个这样的 ul :
<ul id="column3" class="column" runat="server"> </ul>
<ul id="column4" class="column" runat="server"> </ul>
<ul id="column5" class="column" runat="server"> </ul>
我想随机向它们添加列表项:
HtmlGenericControl listItem1 = new HtmlGenericControl("li");
listItem1.Attributes.Add("class", colors[RandString.Next(0, colors.Length -1)]);
column3.Controls.Add(listItem1); //here i wanna to randomize the ul(column3,column4,column5) like i do with the colors
如何做类似的事情。
I have three ul like this :
<ul id="column3" class="column" runat="server"> </ul>
<ul id="column4" class="column" runat="server"> </ul>
<ul id="column5" class="column" runat="server"> </ul>
I wanna to add listitems to them randomly:
HtmlGenericControl listItem1 = new HtmlGenericControl("li");
listItem1.Attributes.Add("class", colors[RandString.Next(0, colors.Length -1)]);
column3.Controls.Add(listItem1); //here i wanna to randomize the ul(column3,column4,column5) like i do with the colors
How to do something like that .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将这些 ul 放入一个数组中
,然后随机选择一个:
请注意,您不需要
uls.Length - 1
因为上限在 下一步 方法。You could put those ul in an array
and then pick a random one:
Notice that you don't need
uls.Length - 1
because the upper bound is exclusive in the Next method.如果您的意思是随机化 ul 的内容,您可以简单地使用颜色的 int 值作为随机定义。
If you mean randomize the ul's content, you could simply use the color's int value as the random definition.