javascript 是否可以从 asp.net 中的 radioButton 列表中禁用一个 listItem
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11466393/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to disable one listItem from radioButton list in asp.net
提问by Satinder singh
I want to disable one listItemfrom RadioButtonListdepend on condition like if querystring contain true
then it will display both the ListItem or else it disabled 2nd listItem ie(External). So user can't access 2nd list item
我想禁用一个的listItem从单选按钮列表取决于条件一样,如果querystring contain true
那么它会同时显示列表项,否则它禁用第二的listItem即(外部)。所以用户不能访问第二个列表项
I have url like
我有这样的网址
abc.com/Account.aspx?type=true
abc.com/Account.aspx?type=true
abc.com/Account.aspx?type=false
abc.com/Account.aspx?type=false
Code On page Account.aspx
页面上的代码 Account.aspx
<asp:RadioButtonList ID="rdodomiantype" runat="server" RepeatDirection="Horizontal" onclick="setTextbox()">
<asp:ListItem Selected="True" Value="0" >Default</asp:ListItem>
<asp:ListItem Value="1" >External</asp:ListItem>
</asp:RadioButtonList>
采纳答案by Satinder singh
Here how i solved with the help of HariHaran
这是我如何在 HariHaran 的帮助下解决的
protected void Page_Load(object sender, EventArgs e)
{
string planType=Request.QueryString["type"];
if (planType == "False")
{
rdodomiantype.Items.Remove(rdodomiantype.Items.FindByValue("1"));
}
}
回答by ewitkows
I didn't want to remove the item from a list, I wanted to disable it like the original poster asked. As such, here's the code I was able to use (EDIT - converted to C# and checking for querystring param based on original post:
我不想从列表中删除该项目,我想像原始海报要求的那样禁用它。因此,这是我能够使用的代码(编辑 - 转换为 C# 并根据原始帖子检查查询字符串参数:
if (!string.IsNullOrEmpty(Request.QueryString["type"]) && Request.QueryString["type"].ToUpper() == "TRUE")
{
foreach (ListItem item in rdoList.Items)
{
if (item.Text == "External")
{
item.Enabled = false;
item.Attributes.Add("style", "color:#999;");
break;
}
}
}
回答by Mahesh KP
Is it necessary to disable one list item? My suggestion is according to the query string value you can bind the dropdown. ie if the query string value is true then you van bind the dropdown with both list item values;
是否有必要禁用一个列表项?我的建议是根据查询字符串值可以绑定下拉列表。即,如果查询字符串值为 true,则您将下拉列表与两个列表项值绑定;
or if the query string value is false you can bind the dropdown with first list item only.
或者如果查询字符串值为 false,您可以仅将下拉列表与第一个列表项绑定。