主要采用的是JQUERY 给radio 添加 name 属性 这样既可以实现这个功能。贴代码,一目了然。
1 <script type="javascript/text" 2 $(function () { 3 $("input:radio").attr("name", "xxx"); 4 }); 5 </script>
接下来看看HTML 怎么写吧
1 <asp:Repeater ID="rptResult" runat="server" OnItemDataBound="rptResult_ItemDataBound"> 2 <ItemTemplate> 3 <tr> 4 <td class="item nowrap max80"> 5 <span> 6 <asp:Label ID="lblFweek" Text='<%# Eval("F_WEEK")%>' runat="server"></asp:Label> 7 </span> 8 </td> 9 <td class="item nowrap max100"> 10 <span> 11 <asp:Label ID="lblFdate" Text='<%# Eval("F_DATE")%>' runat="server"></asp:Label></span> 12 </td> 13 <td class="noItem nowrap max60"> 14 <span> 15 <input id="radio1" type="radio" fdate='<%# Eval("F_DATE")%>' runat="server" fhour="~10:00" 16 fweek='<%# Eval("F_WEEK")%>' /> 17 <asp:Literal ID="Literal1" runat="server"></asp:Literal> 18 </span> 19 </td> 20 <td class="noItem nowrap max100"> 21 <span> 22 <input id="radio2" type="radio" fdate='<%# Eval("F_DATE")%>' runat="server" fhour="10:00~11:00" 23 fweek='<%# Eval("F_WEEK")%>' /> 24 <asp:Literal ID="Literal2" runat="server"></asp:Literal> 25 </span> 26 </td> 27 <td class="noItem nowrap max100"> 28 <span> 29 <input id="radio3" type="radio" fdate='<%# Eval("F_DATE")%>' runat="server" fhour="11:00~13:00" 30 fweek='<%# Eval("F_WEEK")%>' /> 31 <asp:Literal ID="Literal3" runat="server"></asp:Literal> 32 </span> 33 </td> 34 <td class="noItem nowrap max100"> 35 <span> 36 <input id="radio4" type="radio" fdate='<%# Eval("F_DATE")%>' runat="server" fhour="13:00~14:00" 37 fweek='<%# Eval("F_WEEK")%>' /> 38 <asp:Literal ID="Literal4" runat="server"></asp:Literal> 39 </span> 40 </td> 41 <td class="noItem nowrap max100"> 42 <span> 43 <input id="radio5" type="radio" fdate='<%# Eval("F_DATE")%>' runat="server" fhour="14:00~15:00" 44 fweek='<%# Eval("F_WEEK")%>' /> 45 <asp:Literal ID="Literal5" runat="server"></asp:Literal> 46 </span> 47 </td> 48 <td class="noItem nowrap max100"> 49 <span style="font-weight: bold;"> 50 <input id="radio6" type="radio" fdate='<%# Eval("F_DATE")%>' runat="server" fhour="15:00~16:00" 51 fweek='<%# Eval("F_WEEK")%>' /> 52 <asp:Literal ID="Literal6" runat="server"></asp:Literal> 53 </span> 54 </td> 55 <td class="noItem nowrap max100"> 56 <span> <input id="radio7" type="radio" fdate='<%# Eval("F_DATE")%>' runat="server" fhour="16:00~17:00" 57 fweek='<%# Eval("F_WEEK")%>' /> 58 <asp:Literal ID="Literal7" runat="server"></asp:Literal> 59 </span> 60 </td> 61 </tr> 62 </ItemTemplate> 63 </asp:Repeater>
在repeater中有个事件是吧,主要是为了处理绑定的数据用的 ,呵呵 也贴出来吧,用来出来repeater中的控件内容
1 if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) 2 { 3 //判断休息日,不让进行选择 4 if ("星期六".Equals((e.Item.FindControl("lblFweek") as Label).Text) || 5 "星期日".Equals((e.Item.FindControl("lblFweek") as Label).Text)) 6 { 7 (e.Item.FindControl("radio1") as HtmlInputRadioButton).Visible = false; 8 (e.Item.FindControl("radio2") as HtmlInputRadioButton).Visible = false; 9 (e.Item.FindControl("radio3") as HtmlInputRadioButton).Visible = false; 10 (e.Item.FindControl("radio4") as HtmlInputRadioButton).Visible = false; 11 (e.Item.FindControl("radio5") as HtmlInputRadioButton).Visible = false; 12 (e.Item.FindControl("radio6") as HtmlInputRadioButton).Visible = false; 13 (e.Item.FindControl("radio7") as HtmlInputRadioButton).Visible = false; 14 } 15 //工作日时,判断小于当前日期,不进行选择 16 else 17 { 18 string strFDate = (e.Item.FindControl("lblFdate") as Label).Text; 19 DateTime dTime; 20 if (DateTime.TryParse(strFDate, out dTime)) 21 { 22 if (dTime < DateTime.Now.AddDays(-1)) 23 { 24 (e.Item.FindControl("radio1") as HtmlInputRadioButton).Visible = false; 25 (e.Item.FindControl("radio2") as HtmlInputRadioButton).Visible = false; 26 (e.Item.FindControl("radio3") as HtmlInputRadioButton).Visible = false; 27 (e.Item.FindControl("radio4") as HtmlInputRadioButton).Visible = false; 28 (e.Item.FindControl("radio5") as HtmlInputRadioButton).Visible = false; 29 (e.Item.FindControl("radio6") as HtmlInputRadioButton).Visible = false; 30 (e.Item.FindControl("radio7") as HtmlInputRadioButton).Visible = false; 31 } 32 } 33 }