如何用asp.net复选框控件模仿html复选框数组?
我需要在提交时将一组复选框值发送到表单。现在我使用的是普通的旧html,所以它看起来像这样:
<input type="checkbox" name="options[]" />
上面的问题是它不会在回发时维护视图状态,所以我想使用控件(不是列表,而是常规复选框)替换它控制)。
我不想使用列表的原因是因为很难调整布局和位置。
I need to send an array of checkbox values to a form on submit. Right now I am using plain old html, so it looks something like this:
<input type="checkbox" name="options[]" />
The problem with the above is that it doesn't maintain viewstate on postback, so I want to substitute that using the control (not the list, but the regular checkbox control).
The reason I don't want to use a list is because it is hard to tweak the layout and position.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用普通的复选框列表,但添加一个适配器来改变渲染的输出。
这是一个:
http://code.google.com/p/aspnetcontroladapters/wiki/CheckBoxList
You can use the normal checkboxlist but add an adapter to chenge the rendered output.
Here's one:
http://code.google.com/p/aspnetcontroladapters/wiki/CheckBoxList
我决定在这个上坚持使用常规的 html 表单复选框...我失去了视图状态,但它比替代方案更好。
I decided to stick with regular html form checkboxes on this one... I lose the viewstate, but it was better than the alternative.