Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# asp.net使用javascript隐藏dropdownlist中的特定项_C#_Javascript_Asp.net_Dynamic - Fatal编程技术网

C# asp.net使用javascript隐藏dropdownlist中的特定项

C# asp.net使用javascript隐藏dropdownlist中的特定项,c#,javascript,asp.net,dynamic,C#,Javascript,Asp.net,Dynamic,我正在使用ASP.NET,并动态填充我的DropDownList。 这是我的密码: DataTable dtList = new DataTable(); dtList.Columns.Add("Name"); dtList.Columns.Add("Type"); foreach (DataDefinitionResponse dr in _dr) { if (dr.Type == "Dropdown")

我正在使用ASP.NET,并动态填充我的DropDownList。 这是我的密码:

  DataTable dtList = new DataTable();
        dtList.Columns.Add("Name");
        dtList.Columns.Add("Type");

foreach (DataDefinitionResponse dr in _dr)
        {
            if (dr.Type == "Dropdown")
            {
                string[] strSplit = dr.ListValue.Split('|');
                List<string> lst = new List<string>();

                foreach (string word in strSplit)
                {
                    DataRow row = dtList.NewRow();
                    row["Name"] = word;
                    row["Type"] = dr.Name;
                    dtList.Rows.Add(row);
                }
            }
        }

ddlFieldList.DataSource = dtList;
        ddlFieldList.DataTextField = "Name";
        ddlFieldList.DataValueField = "Type";
        ddlFieldList.DataBind();
DataTable dtList=newdatatable();
dtList.Columns.Add(“名称”);
dtList.Columns.Add(“类型”);
foreach(数据定义响应dr in_dr)
{
如果(dr.Type==“下拉列表”)
{
字符串[]strSplit=dr.ListValue.Split(“|”);
List lst=新列表();
foreach(strSplit中的字符串字)
{
DataRow row=dtList.NewRow();
行[“名称”]=字;
行[“类型”]=医生姓名;
dtList.Rows.Add(行);
}
}
}
ddlFieldList.DataSource=dtList;
ddlFieldList.DataTextField=“Name”;
ddlFieldList.DataValueField=“Type”;
ddlFieldList.DataBind();
现在我只想在选择另一个DropDownList时使用Javascript隐藏一个特定的项目。 我没有在这里使用SelectedIndexChanged。我必须使用Javascript

请有人帮我做这个


Thx

我认为您无法使用JavaScript操作DropDownList并“侥幸逃脱”,因为当页面随后被发布回服务器时,ASP.NET将检测到DropDownList已被“篡改”,并将抛出异常

您可以设置一些标志来停止错误,但不太可能在代码隐藏中使用DropDownList

通常情况下,您可以使用
SelectedIndexChanged
(我知道您说过您不想这样做)实现您想要做的事情,并将控件放入
UpdatePanel
或类似文件中,以避免整页回发/刷新。

函数删除()
function Remove()
{
var DropDownList=document.getElementById('<%=DropDownList1.ClientID%>');
alert(DropDownList.value);
for(i=DropDownList.length-1; i>=0; i--) 
{
    if(DropDownList.options[i].selected)
    {
       DropDownList.remove(i);         
    }
}
}
{ var DropDownList=document.getElementById(“”); 警报(DropDownList.value); 对于(i=DropDownList.length-1;i>=0;i--) { if(DropDownList.options[i].选中) { DropDownList.remove(i); } } }