0
我有一個單選按鈕列的gridview。我有一個JavaScript功能,只允許用戶點擊一個單選按鈕。你第一次點擊gridview沒有任何反應。每次點擊後,工作正常。爲什麼第一次點擊gridview中的單選按鈕什麼也不做?
更新: 如果我直接單擊單選按鈕,它確實工作的第一次,但如果我點擊該行,我必須單擊兩次。
<script type="text/javascript">
function SelectSingleRadiobutton(rdbtnid) {
var rdBtn = document.getElementById(rdbtnid);
var rdBtnList = document.getElementsByTagName("rbTypeGroup");
for (i = 0; i < rdBtnList.length; i++) {
if (rdBtnList[i].type == "radio" && rdBtnList[i].id != rdBtn.id) {
rdBtnList[i].checked = false;
}
}
}
</script>
<asp:GridView ShowHeader="false" SkinID="noborder" runat="server" ID="gvType" AutoGenerateColumns="false"
OnRowDataBound="gvType_RowDataBound" ClientIdMode="Predictable">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButton ID="optValue" runat="server" Name="options" Style="cursor: default;" Tag="rbTypeGroup" OnClick="SelectSingleRadiobutton(this.id)"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" />
<asp:BoundField DataField="Description" />
</Columns>
</asp:GridView>
protected void gvType_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HibConfig.IncidentType type = (HibConfig.IncidentType)e.Row.DataItem;
RadioButton rdo = ((RadioButton)e.Row.FindControl("optValue"));
rdo.Checked = incident.Type.Id == type.Id ? true : false;
e.Row.Attributes.Add("onclick", string.Format("document.getElementById('{0}').click();", rdo.ClientID));
e.Row.Attributes.Add("dataId", type.Id.ToString());
}
}