2

如果选择了 4 个属性列表中的 2 个选项之一,我的项目中有单选按钮应该被禁用。这是我的代码:

<asp:DropDownList ID="drpLType" runat="server" CssClass="drp">
 <asp:ListItem Value="0" Selected="True">Professional</asp:ListItem>
 <asp:ListItem Value="1">Enterprise</asp:ListItem>
 <asp:ListItem Value="2">Maintanence</asp:ListItem>
 <asp:ListItem Value="3">Reporting</asp:ListItem>
</asp:DropDownList>

我为此目的使用了javascript:

function funMeapSupportValidate(val)
{
  switch(val)
    {
        case "0" :                             
            document.getElementById('<%=this.rdoMeapSupport.ClientID%>').disabled = false; 
            break;
        case "1" :
            document.getElementById('<%=this.rdoMeapSupport.ClientID%>').disabled = false; 
            break;                
        case  "2" :
            document.getElementById('<%=this.rdoMeapSupport.ClientID%>').check = false;   
            document.getElementById('<%=this.rdoMeapSupport.ClientID%>').disabled = true; 
            break;                
        case  "3" :
            document.getElementById('<%=this.rdoMeapSupport.ClientID%>').check = false;   
             document.getElementById('<%=this.rdoMeapSupport.ClientID%>').disabled = true; 
            break;                
        default:
            break;
    }
}

在我的后端代码:

protected void drpLType_SelectedIndexChanged(object sender, EventArgs e)
{
    if (drpLType.SelectedValue == "Professional")
    {
        rdoMeapSupport.Enabled = true;
    }

    if (drpLType.SelectedValue == "Enterprise")
    {
        rdoMeapSupport.SelectedValue = null;
        rdoMeapSupport.Enabled = true;
    }

    if ((drpLType.SelectedValue == "Maintanence") || (drpLType.SelectedValue == "Reporting"))
    {
        rdoMeapSupport.Enabled = false;
        rdoMeapSupport.ClearSelection();
    }

}

现在的问题是我的网站上有两个按钮。每当我单击这些按钮时,即使我选择了Maintenance或,单选按钮也会被激活Reporting。我该如何禁用它?

在我的页面加载:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        Tab1.CssClass = "Clicked";
        MainView.ActiveViewIndex = 0;

        if (drpLType.SelectedValue == "Professional")
        {
            rdoMeapSupport.Enabled = true;
            rdoMeapSupport.SelectedValue = "Yes";
        }

        drpLType_SelectedIndexChanged();
    }

    drpLType.Attributes.Add("onchange", "javascript:funMeapSupportValidate(this.value);");
}
4

2 回答 2

0

嗯,我用这个

<INPUT type="radio" name="myButton" value="theValue"
onclick="this.checked=false;
alert('Sorry, this option is not available!')">
于 2012-12-19T04:26:55.393 回答
0

我终于通过以下方式解决了错误。

protected void drpLType_SelectedIndexChanged(object sender, EventArgs e)
{
  if (drpLType.SelectedValue == "1")
  {
   rdoMeapSupport.Enabled = true;
  }

  if (drpLType.SelectedValue == "2")
  {
   rdoMeapSupport.SelectedValue = null;
   rdoMeapSupport.Enabled = true;
  }

  if ((drpLType.SelectedValue == "3") || (drpLType.SelectedValue == "4"))
  {
   rdoMeapSupport.Enabled = false;
   rdoMeapSupport.ClearSelection();
  }
}
于 2012-12-19T09:30:24.037 回答