C# 限制中继器两列中的单选按钮选择
在第一列中,我显示了学院列表。每个学院都有多个课程,显示在第二列中 对用户选择的限制: 当用户选择一所学院(比如麻省理工学院)时,他应该被允许只选择与所选学院相对应的课程(本例中为计算机科学和机械工程) 如何使用jQuery实现此功能 我正在将以下数据绑定到嵌套的中继器中C# 限制中继器两列中的单选按钮选择,c#,jquery,asp.net,user-controls,radio-button,C#,Jquery,Asp.net,User Controls,Radio Button,在第一列中,我显示了学院列表。每个学院都有多个课程,显示在第二列中 对用户选择的限制: 当用户选择一所学院(比如麻省理工学院)时,他应该被允许只选择与所选学院相对应的课程(本例中为计算机科学和机械工程) 如何使用jQuery实现此功能 我正在将以下数据绑定到嵌套的中继器中 public string currentCollege { get; set; } Dictionary<string, List<string>> colleges; cla
public string currentCollege { get; set; }
Dictionary<string, List<string>> colleges;
class College
{
public College(string s)
{
Course = s;
}
public string Course { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
colleges = new Dictionary<string, List<string>>();
colleges.Add("mit", new List<string>(new string[] { "computer science", "mechanical engg." }));
colleges.Add("caltech", new List<string>(new string[] { "electrical engg", "cryptography"}));
colleges.Add("harvard", new List<string>(new string[] { "language", "arts", "science" }));
rptColleges.DataSource = colleges;
rptColleges.DataBind();
}
protected void rptColleges_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rptCourseNow = (e.Item.FindControl("rptCourses") as Repeater);
rptCourseNow.DataSource = colleges[currentCollege];
rptCourseNow.DataBind();
}
}
公共字符串currentCollege{get;set;}
字典学院;
班级学院
{
公立学院(s)
{
课程=s;
}
公共字符串课程{get;set;}
}
受保护的无效页面加载(对象发送方、事件参数e)
{
学院=新字典();
添加(“mit”,新列表(新字符串[]{“计算机科学”,“机械工程”);
添加(“加州理工学院”,新列表(新字符串[]{“电气工程”,“密码术”});
添加(“哈佛”,新列表(新字符串[]{“语言”,“艺术”,“科学”});
rptColleges.DataSource=学院;
rpt.DataBind();
}
受保护的无效RPTU项数据绑定(对象发送方、RepeaterItemEventArgs e)
{
如果(e.Item.ItemType==ListItemType.Item | | e.Item.ItemType==ListItemType.AlternatingItem)
{
中继器rptCourseNow=(e.Item.FindControl(“rptCourses”)作为中继器);
rptCourseNow.DataSource=学院[当前学院];
rptCourseNow.DataBind();
}
}
标记如下所示-
<asp:Repeater ID="rptColleges" runat="server" OnItemDataBound="rptColleges_ItemDataBound">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:RadioButton ID="rbCollege" runat="server" value=<%# DataBinder.Eval((KeyValuePair<string, List<string>>)Container.DataItem, "Key") %> />
<%# currentCollege = (string)DataBinder.Eval((KeyValuePair<string, List<string>>)Container.DataItem, "Key") %>
</td>
<td>
<asp:Repeater ID="rptCourses" runat="server">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:RadioButton ID="rbCourse" value="<%#Container.DataItem %>" runat="server" />
<%#Container.DataItem %>
</li>
</ItemTemplate>
<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>
</td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:Repeater>
-
谢谢您的帮助。如果我理解正确,您希望将单选按钮分组到一个学院。您可以使用RadioButton的GroupName属性使单选按钮的部分相互排斥 查看此链接:
请告诉我们您的应用程序试图实现的目标。我们不是你的同事,不知道你在做什么。“现在你的问题听起来有点含糊。”小毛,我本来可以说得更清楚一些的。更新问题清楚吗?