使用Javascript在Gridview中禁用DropDownList

使用Javascript在Gridview中禁用DropDownList,javascript,jquery,asp.net,Javascript,Jquery,Asp.net,我正在努力进行javascript编程,需要帮助 我正在尝试禁用gridview中客户端的6个下拉列表。下面是我当前的javascript,除了最后一行,我试图禁用其中一个下拉列表。我认为问题在于下拉列表在gridview中,java无法找到它们。我怎么找到他们 <script> function EnableAndColorButtons() { document.getElem

我正在努力进行javascript编程,需要帮助

我正在尝试禁用gridview中客户端的6个下拉列表。下面是我当前的javascript,除了最后一行,我试图禁用其中一个下拉列表。我认为问题在于下拉列表在gridview中,java无法找到它们。我怎么找到他们

<script>
                        function EnableAndColorButtons() {
                            document.getElementById('<%= Submit.ClientID %>').disabled = false;
                            document.getElementById('<%= Submit.ClientID %>').style.background = "Lime";
                            document.getElementById('<%= Submit.ClientID %>').style.borderColor = "Green";
                            document.getElementById('<%= Cancel.ClientID %>').disabled = false;
                            document.getElementById('<%= Cancel.ClientID %>').style.background = "lightcoral";
                            document.getElementById('<%= Cancel.ClientID %>').style.borderColor = "Red";                                   
                            document.getElementById('<%= InfoLbl.ClientID %>').innerHTML = '(Continue to make changes or click submit if finished)';                                
                            document.getElementById('<%= MakeChangeslbl.ClientID %>').innerHTML = 'You must click "Submit Changes" or "Cancel Changes" above before making Assignment changes below!';
                            //The above is working, but the below is not probaly because the drop down lists are within gridview1
                            document.getElementById('<%= DropDownList1.ClientID %>').disabled = true;
                        }
                    </script>

函数EnableAndColorButtons(){
document.getElementById(“”).disabled=false;
document.getElementById(“”).style.background=“Lime”;
document.getElementById(“”).style.borderColor=“绿色”;
document.getElementById(“”).disabled=false;
document.getElementById(“”).style.background=“lightcoral”;
document.getElementById(“”).style.borderColor=“红色”;
document.getElementById(“”).innerHTML='(继续进行更改,如果完成,请单击提交);
document.getElementById(“”).innerHTML='在进行下面的分配更改之前,必须单击上面的“提交更改”或“取消更改!”;
//上面的操作正常,但下面的操作可能不正常,因为下拉列表位于gridview1中
document.getElementById(“”).disabled=true;
}
下拉列表所在的My Gridview如下所示:

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource3" DataTextField="FullDetails" DataValueField="FullDetails" Font-Size="Medium" Height="50px" OnDataBinding="DropDownlist1_DataBinding1" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Width="230px">
                                            </asp:DropDownList>

我终于想出了一个解决方案

我所做的是用chrome浏览器右键单击我的下拉框,然后单击inspect element。在那里,我发现dropbox的id等于“GridView1\u DropDownList 1\u 0”

然后我在Javascript中执行了以下操作,它成功了

var ddl1 = document.getElementById("GridView1_DropDownList1_0");
ddl1.disabled = true

尝试将autopostback更改为false并检查它是否工作,我相信您编写的javascript正在工作,只是回发导致了此处的问题。我需要autopostback才能使下拉列表的功能正常工作。我确实尝试将autopostback更改为false进行测试,但下拉列表未被禁用。该死。。。我以为这对某人来说很容易。。。