gridview编辑模板列中有DDL1和DDL2,现在1能通过AJAX联动设置2的ITEM,但点击更新按钮时出现如题:回发或回调参数无效
    protected override void Render(HtmlTextWriter writer)
    {
      Page.ClientScript.RegisterForEventValidation("ctl00_ContentPlaceHolder1_GridView1_ctl02_DropDownList2");
      base.Render(writer);
    }
用了也没效果。
RegisterForEventValidation怎么用?

解决方案 »

  1.   

    两个DDL都是asp:DropDownList
      

  2.   

    ”通过AJAX联动设置2的ITEM“是什么意思?怎么可能在客户端去设置下拉 Item?
      

  3.   

    页面上有着巨大的状态数据,难道你破坏了 ViewState 数据?
      

  4.   

    //客户列表
    gv_customer_changed=function(gv_rowindex)
    {
        var customer_ddl=$("#ctl00_ContentPlaceHolder1_GridView1_ctl0" + (gv_rowindex + 2) + "_DropDownList1");
        var customer_ddl_value=customer_ddl.find('option:selected').val();
        var customercode_ddl=$("#ctl00_ContentPlaceHolder1_GridView1_ctl0" + (gv_rowindex + 2) + "_DropDownList2");    for(var i=customercode_ddl.get(0).options.length -1;i>0;i--){
            $("#ctl00_ContentPlaceHolder1_GridView1_ctl0" + (gv_rowindex + 2) + "_DropDownList2 option:last").remove();
        }
        if(customer_ddl.get(0).selectedIndex == 0){
            throw '-1';
        }   
        $.post( "../ajax/sc.ashx",
            {part_flag:"gv1.ddl1",p_customer_ddl_value:customer_ddl_value},
            function(data){
                if(!data.hasOwnProperty("returnnull")){
                    for(var p in data){
                        customercode_ddl.append("<option value='" + p + "'>" + data[p] + "</option>");
                    }
                }
            },
            "json"
        );
    }
    这样用DDL1设置DDL2
      

  5.   

    DDL1能成功设置DDL2
      

  6.   

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='LightSteelBlue'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                if (((int)e.Row.RowState) == 0 || ((int)e.Row.RowState) == 1)
                {
                    ((LinkButton)e.Row.Cells[0].Controls[2]).Attributes.Add("onclick", "return confirm(\"确定要删除此记录吗?\");");
                }
                else if (((int)e.Row.RowState) == 4 || ((int)e.Row.RowState) == 5)
                {
                    ((DropDownList)e.Row.FindControl("DropDownList1")).Attributes.Add("onchange", "gv_customer_changed(" + e.Row.RowIndex + ");");
                }
            }
        }
      

  7.   

    设置 options 并不会破坏 ViewState,应该是你别的地方的代码破坏了页面核心状态。不过这里简单可以看出有几个 asp.net 编程基本知识:
    1.  控件的客户端 id 要使用控件的 ClientID 属性来动态获取,不要随便手动写死。2. DropdownList 在服务器端实际上要从 ViewState 中重建 Items,然后跟提交的Value的值比对,来判断 SelectedIndex。所以你客户端无论怎么修改 option 也不会修改服务器端的 Items,因此也就无法正确地得到 SelectedIndex。所以对于 DropdownList来说,其实就只好”放弃“,你应该使用 HiddenField 来回传选择值,不要再从服务器端去取 DDL 的选择 Item。
      

  8.   

           Page.ClientScript.RegisterForEventValidation("ctl00_ContentPlaceHolder1_GridView1_ctl02_DropDownList2");应该注册DDL1还是DDL2的UNIQUE.ID
      

  9.   

    gridview编辑模板列感觉不适合用AJAX联动两个DDL,要辅助的东西太多了,自己都是硬着头皮写下去,越写越绕,为每个DDL要准备几个HiddenField,