ASP.NET、Telerik RadListView、RadioButtonList 和 CustomValidator 问题
我正在开发一个 ASP.NET,其中有一个 RadListView (Telerik)。每个 RadListView 的项目内都有一个带有两个单选按钮的 RadioButtonList。我需要做的是:
- 第一次加载页面时,必须默认选择两个单选按钮之一;
- 在回发时,我必须检查用户是否选择了另一个(尝试使用 CustomValidator 来完成);
- 回发时我必须保留 RadioButtonLists 的状态。
我知道如何才能做到这一点吗?
这是我的代码的一部分:
<telerik:RadListView ID="rlvContracts" runat="server">
<ItemTemplate>
<fieldset style="margin-bottom: 30px;">
<table cellpadding="0" cellspacing="0">
[...]
<asp:RadioButtonList runat="server" EnableViewState="true" ID="rblContract" RepeatDirection="Horizontal">
<asp:ListItem Value="1" Text="Accept"></asp:ListItem>
<asp:ListItem Value="0" Text="I do not accept" Selected="True"></asp:ListItem>
</asp:RadioButtonList>
[...]
<!-- Custom Validator Here -->
[...]
</table>
</fieldset>
</ItemTemplate>
</telerik:RadListView>
感谢任何帮助(甚至教程的链接)
提前致谢, 丹尼尔
I'm working on an ASP.NET where I have a RadListView (Telerik). Inside every RadListView's item there's a RadioButtonList with two radio buttons. What I need to do is:
- on the first time the page gets loaded one of the two radio buttons must be selected by default;
- on postback I have to check that the user has selected the other one (trying to do it with a CustomValidator);
- on post back I have to keep the status of the RadioButtonLists.
Any idea on how can I do that?
Here's part of my code:
<telerik:RadListView ID="rlvContracts" runat="server">
<ItemTemplate>
<fieldset style="margin-bottom: 30px;">
<table cellpadding="0" cellspacing="0">
[...]
<asp:RadioButtonList runat="server" EnableViewState="true" ID="rblContract" RepeatDirection="Horizontal">
<asp:ListItem Value="1" Text="Accept"></asp:ListItem>
<asp:ListItem Value="0" Text="I do not accept" Selected="True"></asp:ListItem>
</asp:RadioButtonList>
[...]
<!-- Custom Validator Here -->
[...]
</table>
</fieldset>
</ItemTemplate>
</telerik:RadListView>
Any help (even links to tutorials) is apreciated
Thanks in advance,
Daniele
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了执行第一步,您可以遵循您在上面的代码中发布的想法(所选 RadioButton 的声明性设置),或者您可以通过执行以下操作以编程方式设置它:
如您所见,您必须访问通过控件的 Items 集合的特定 RadListView Item。一旦获得了您感兴趣的项目,您就可以使用 FindControl() 方法,该方法将控件的 ID 作为字符串。
至于验证部分,这是一个可能的实现:
ASPX:
C#:
这应该确保在回发时选择“我接受”RadioButton。
In order to do the first step you can either follow the idea that you posted in your code above (declarative setting of the selected RadioButton) or you could programmatically set it by doing something along the following lines:
As you can see you have to access the particular RadListView Item via the Items collection of the control. Once you have the item you're interested in you can just use the FindControl() method which takes the ID of your control as a string.
As for the validation part this is a possible implementation:
ASPX:
C#:
That should take care of all ensuring that the "I Accept" RadioButton is selected upon PostBack.