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; } } }
时间: 2024-10-16 04:55:06