有一个GridView 
  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].Attributes.Add("onclick", "jsFunctionName('" + e.Row.Cells[1].Text.ToString().Trim() + "','" + e.Row.Cells[2].Text.ToString().Trim() + "')");
          }
    }在前台的head中
<head id="Head1" runat="server">
    <title>无标题页</title>
    <script language="javascript" type="text/javascript">       function jsFunctionName(a1,a2)//类别 名称 规格
        { var str1=a1;var str2=a2;     
          window.document.getElementById("txtA").value=str1;
          window.document.getElementById("txtB").value=str2;
        }          </script></head>如果在GridView中  e.Row.Cells[1].Text  为空的话   传到前台  a1就变成“&nbsp;”了,
除了下面这么办  还有其他方法吗,我的GridView列很多的下面这样写很费时间的。
       function jsFunctionName(a1,a2)//类别 名称 规格
        { var str1=a1;var str2=a2;   
           if(str1!="&nbsp;"){
          window.document.getElementById("txtA").value=str1;}
           if(str2!="&nbsp;"){
          window.document.getElementById("txtB").value=str2;}
        }

解决方案 »

  1.   

    方法很多,不过下面这样没问题,不需要改吧
          function jsFunctionName(a1,a2)//类别 名称 规格 
            {   
              window.document.getElementById("txtA").value=a1;} 
              window.document.getElementById("txtB").value=a2;} 
            } 
      

  2.   

    改下:
          function jsFunctionName(a1,a2)//类别 名称 规格
            { 
              window.document.getElementById("txtA").value=a1;
              window.document.getElementById("txtB").value=a2;
            }
      

  3.   

    不想前台写,就后台传数据的时候先replace一下
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
        { 
            if (e.Row.RowType == DataControlRowType.DataRow) 
            { 
                e.Row.Cells[0].Attributes.Add("onclick", "jsFunctionName('" + e.Row.Cells[1].Text.ToString().Trim().Replace("&nbsp;", ""); + "','" + e.Row.Cells[2].Text.ToString().Trim().Replace("&nbsp;", ""); + "')"); 
              } 
        } 
      

  4.   


      protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
        { 
            if (e.Row.RowType == DataControlRowType.DataRow) 
            { 
                e.Row.Cells[0].Attributes.Add("onclick", "jsFunctionName('" + Server.HtmlDecode(e.Row.Cells[1].Text).Trim() + "','" + Server.HtmlDecode(e.Row.Cells[2].Text).Trim() + "')"); 
              } 
        } 
      

  5.   

    if(str1!="&nbsp;"){ 
              window.document.getElementById("txtA").value=str1;} ------------------------------------------------------------------转换后 str1 从 "&nbsp;" 变成 "" 了按照现有代码的逻辑 根本无意义
      

  6.   

    &nbsp;产生是字段中null产生的,你可以在GridView绑定的时候将null值改为一个空格!
    这样代码无需改动!!
    只要加GridView前台代码,如下:
    ......
    <asp:BoundField DataField="字段" HeaderText="xxxx" NullDisplayText=" " >
      

  7.   

    我ko 这也行、、、CSDN人才真多