在GridView下有很多DropDownList,修改之后是可以变灰,通过GridView1_RowDataBoundif (e.Row.RowType == DataControlRowType.DataRow)
        {
            if ((e.Row.FindControl("DropDownList1") as DropDownList).Enabled == false)
            {
                (e.Row.FindControl("DropDownList1") as DropDownList).CssClass = "DropListStyle1";
            }
}可以让其变灰,但由于页面数据量大,修改再绑定就需要等待很久,现在我想一点击就直接变灰
<asp:DropDownList ID="DropDownList1" runat="server" CssClass="DropListStyle" SelectedValue='<%# Eval("ReserveState") %>'
                                                Enabled='<%#Eval("ReserveState").ToString()=="0"%>' OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
                                                AutoPostBack="true">
                                                <asp:ListItem Value="0">未预约</asp:ListItem>
                                                <asp:ListItem Value="1">已预约</asp:ListItem>
                                            </asp:DropDownList>
----------------------------DropDownList1_SelectedIndexChanged------------
((DropDownList)(sender)).Enabled = false;-----这里是我想直接变灰的代码,为什么没有反应呢?

解决方案 »

  1.   

    SelectedIndexChanged 这个事件只有在你选择项改变的时候才响应,不是你按就响应
      

  2.   

    试试,JSCRIPT客户端代码,onClick之js事件
      

  3.   

    不过ID确定不了
    <select name="GridView1$ctl02$DropDownList1" 类似这样的,是服务器控件,所以ID就是自动生成的
    如果使用客户端控件下拉框 其ID就可以知道,不过实现我另外的问题就比较困难和麻烦
      

  4.   

    用JS实现,GridView里面生成的控件的客户端ID,是有顺序、规律的,用JS做个循环就可以了
      

  5.   

    在GridView的GridView1_RowDataBound不能实现你的操作?
    if (e.Row.RowType == DataControlRowType.DataRow) 
            if ((e.Row.FindControl("DropDownList1") as DropDownList).Enabled == false) 
            { 
                //JS代码绑定
            } 
    }
    这样当页面生成后,所有DropDownList1都绑定了一个JS事件,DropDownList用C#让他变色,是需要有post的,也就是每次需要刷新页面,不慢才怪了。。
      

  6.   

             <asp:DropDownList ID="DropDownList1" runat="server">
                <asp:ListItem>a</asp:ListItem>
                <asp:ListItem>b</asp:ListItem>
                <asp:ListItem>c</asp:ListItem>
                <asp:ListItem>d</asp:ListItem>
            </asp:DropDownList>DropDownList1.Attributes.Add("onchange", "this.disabled=true;");
      

  7.   

    就是在页面生成的时候给DropDownList1控件动态的加一个onclick的JS事件,反正你所有的控件都是一个事件,所以就简单多了
      

  8.   

    @zcl24这位大虾的回答,我觉得好像是可以,不过试了一下还是不可以
    那个onchange的事件需要等待??有点奇怪的呵呵~~~