var cc=document.getElementById("<%=mydatagrid.ClientID%>"); 

解决方案 »

  1.   

    你的datagrid是空的呀,没值啊,先赋值吧。
      

  2.   

    用了Ivan的方法,还是同样的错误:
    Microsoft JScript runtime error: 'null' is null or not an objectparss:datagrid是没有指定datasource,但这个对象是存在的,你说的赋值是指赋什么值?
      

  3.   

    实际上这个动态绑定datagrid的是在网上搜的一个例子,我往上套用的。但是在
    function get_DataGrid_Result_CallBack(response) 这个里面引用datagrid不成功。提示null.
    卡住不动了。
        <p title="Warehouse Web version-Location Transfer ">
            <asp:DataGrid ID="mydatagrid" runat="server" AutoGenerateColumns="False" Height="176px" 
                Width="693px">
            </asp:DataGrid>
        </p>function DataGridResult()
    {
        var PONO=document.getElementById("txtPONO");
        var Lot=document.getElementById("DropDLLot");
        var Shade=document.getElementById("DropDLShade");
        var Location1=document.getElementById("DropDLLocation1");
        var Location2=document.getElementById("DropDLLocation2");
        AjaxTransfer.getDataGrid(PONO.value,Lot.item(Lot.selectedindex).text,Shade.item(Shade.selectedindex).text 
            ,Location1.item(Location1.selectedindex).text, Location2.item(Location2.selectedindex).text,get_DataGrid_Result_CallBack );
            
        document.getElementById("DropDLLot").disabled = false;
        document.getElementById("DropDLShade").disabled = false;
        document.getElementById("DropDLLocation1").disabled = false;
        document.getElementById("DropDLLocation2").disabled = false;
    //    document.getElementById("DropDLTL1").Text = "";
    //    document.getElementById("DropDLTL2").Text = "";
        
    }function get_DataGrid_Result_CallBack(response)
    {
       if (response.value != null)
        {
        var ds = response.value;
        if(ds != null && typeof(ds) == "object" && ds.Tables != null)
        {
            var cc=document.getElementById('mydatagrid'); 
                cc.innerHTML=AjaxTransfer.RefreshDataGrid(ds.Tables[0]).value;        }
        }
    }        <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
            Public Function getDataGrid(ByVal PONO As String, ByVal Lot As String, ByVal Shade As String _
            , ByVal Loc1 As String, ByVal Loc2 As String) As DataSet
                Dim ds As DataSet
                ds = GetDataSet(PONO, "LOC2", Lot, Shade, Loc1, Loc2)
                Return ds        End Function
            <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
            Private Function RefreshDataGrid(ByRef dtLocation As DataTable) As String            '//实例化一个datagird类并设置好数据源 
                Dim dg As DataGrid = New DataGrid()
                dg.DataSource = dtLocation
                dg.DataBind()
                '//实例化一个HtmlTextWriter的类 
                Dim strb As System.Text.StringBuilder = New System.Text.StringBuilder()
                Dim sw As System.IO.StringWriter = New System.IO.StringWriter(strb)
                Dim htw As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(sw)
                '//执行控件的render并输出到HtmlTextWriter里 
                dg.RenderControl(htw)
                Dim s As String = strb.ToString()
                Return s '//最后就是返回这个html啦 
            End Function
      

  4.   

    上面的代码是通过单击button后触发function DataGridResult()开始执行的。