使用 RadioButtonList 时可以控制标签吗?
这个
protected void Page_Load(object sender, EventArgs e) {
RadioButtonList1.Items.Add(new ListItem("London","1"));
RadioButtonList1.Items.Add(new ListItem("Paris", "2"));
}
和这个
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatLayout="Flow">
</asp:RadioButtonList></div>
会产生类似这样的 HTML
<input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="1" />
<label for="RadioButtonList1_0">London</label>
<input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="2" />
<label for="RadioButtonList1_1">Paris</label>
,但我真正想要的是这个,注意 标记中的类。
<input type="radio" name="Event" id="whatever" value="1" />
<label for="London" class="London">London</label>
<input type="radio" name="Event" id="whatever" value="2" />
<label for="Paris" class="Paris">Paris</label>
我可以将 cssClass 添加到自动生成的 标签?
This
protected void Page_Load(object sender, EventArgs e) {
RadioButtonList1.Items.Add(new ListItem("London","1"));
RadioButtonList1.Items.Add(new ListItem("Paris", "2"));
}
and this
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatLayout="Flow">
</asp:RadioButtonList></div>
produce HTML something like this
<input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="1" />
<label for="RadioButtonList1_0">London</label>
<input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="2" />
<label for="RadioButtonList1_1">Paris</label>
but what I really want is this, note the class in the <label>
tag.
<input type="radio" name="Event" id="whatever" value="1" />
<label for="London" class="London">London</label>
<input type="radio" name="Event" id="whatever" value="2" />
<label for="Paris" class="Paris">Paris</label>
Can I add a cssClass to the automatically generated <label>
tag?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以从
RadioButtonList
继承,如图所示 此处或此处。最后一个链接可能更符合您的要求。
您应该只需要重写 RenderItem 方法,如下所示:
注意,我实际上尚未编译上面的代码,但应该足以指导您正确的方向:)
You could inherit from
RadioButtonList
, like shown here or here.The last link is probably more in line with what you want.
You should only need to override the RenderItem method, like so:
Note, I have not actually compiled above code, but should be enough to guide you in a proper direction :)
我不是 ASP.NET 专业人士,但我确实知道您可以通过使用子选择器轻松控制具有已知 ID 的元素内 LABEL 的显示。
I'm not an ASP.NET pro, but I do know that you can easily control the presentation of the LABEL's inside your an element with a known ID by using child selectors.