<script type="text/javascript">
     function getCodes(id)
    {
          backPage(id);
    }
   var main=window.dialogArguments;
   function backPage(id)
   {
    main.EmployeeID=id;  
    main.getCode();
        window.close();
}    </script>后台调用。。
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //e.Row.Cells[1].Attributes.Add("class", "text");
            //e.Row.Attributes["style"] = "Cursor:hand";
            //e.Row.Attributes.Add("onmouseover", "this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#FFFBD1';cursor='hand'");
            //e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor");
            Label lbdepart = new Label();
            lbdepart = (Label)e.Row.FindControl("lbdepart");
            HiddenField code = new HiddenField();
            HiddenField id = new HiddenField();
            HiddenField name = new HiddenField();
            code = (HiddenField)e.Row.FindControl("code");
            id = (HiddenField)e.Row.FindControl("EmpID");
            name = (HiddenField)e.Row.FindControl("name");
            e.Row.Attributes.Add("OnDblClick", "getCodes('" + id.Value + "');");
        }
    }
页面生成HTML之后
有的<tr OnDblClick="gs('327#皮红生
');">这里自动换行了。。就报 未结束的字符串常量
没有自动换行的地方就很正常……大侠们帮忙一下啊。。急得想哭了。。

解决方案 »

  1.   

    e.Row.Attributes.Add("OnDblClick", "getCodes('" + id.Value + "');"); 怎么变成 
    <tr OnDblClick="gs('327#皮红生
    ');">这里自动换行了
      

  2.   

    id 查一下你的 id 值为啥会有换行?
      

  3.   

    <tr OnDblClick="gs('327#皮红生 
    ');">你传过来的参数 '327#皮红生 ' 里面如果有\r\n 就有可能出现那种情况,
    试着传递参数的时候先Replace一下
    str.Replace("\r", "\\r").Replace("\n", "\\n");
      

  4.   

    string.Replace("\r"," ");可以尝试判断字符串啊,
    5楼正解的