·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP.NET网站开发 >> [转]Gridview中实现RadioButton单选效果
HTML
<asp:TemplateField ItemStyle-Width="22px"> <ItemTemplate> <asp:RadioButton ID="radButtonControl" GroupName="group1" runat="server" /> </ItemTemplate> </asp:TemplateField>
CS
PRotected void gvWorkPlanList_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { RadioButton rb = (RadioButton)e.Row.FindControl("radButtonControl"); if (rb != null) rb.Attributes.Add("onclick", "onRadiobuttonClick('" + this.gvWorkPlanList.ClientID + "','" + rb.ClientID + "')"); } }
JS
/**//*传入的GridviewClientID和所选的RadioButton ClientID**/ function onRadiobuttonClick(gvControlID,selectedControlId) { var inputs = document.getElementById(gvControlID).getElementsByTagName("input"); for(var i=0; i <inputs.length; i++) { if(inputs[i].type=="radio") { if(inputs[i].id==selectedControlId) inputs[i].checked = true; else inputs[i].checked = false; } } }