在服务端调用客户端脚本,将数据通过调用客户端脚本函数赋值给页面的文本框。有时候某个数据可能为空,则通过调用脚本函数赋值时文本框的内容为[&nbsp],怎么样解决这个问题???
求救...
客户端脚本函数为 function rekey(num,name) 
        { 
            document.getElementById("txtNum").value=num; 
            document.getElementById("txtName").value=name ;}c#代码为 e.Row.Attributes.Add("onclick", "rekey('" + e.Row.Cells[0].Text + "','" + e.Row.Cells[1].Text + "');

解决方案 »

  1.   

    ok在服务器端声明两个变量
    string str1="",str2="";
    str1= e.Row.Cells[0].Text.Trim();
    if(str1=="")
    {
    str1="&nbsp";
    }str2= e.Row.Cells[1].Text.Trim();
    if(str2=="")
    {
    str2="&nbsp";
    }
    e.Row.Attributes.Add("onclick", "rekey('" + str1 + "','" + str2+ "');
      

  2.   

    直接判断不就好了
    string a = e.Row.Cells[0].Text;
    string b = e.Row.Cells[1].Text;
    if(a=="")
    {
     a="[&nbsp]";
    }
    if(b=="")
    {
     b="[&nbsp]";
    }
    e.Row.Attributes.Add("onclick", "rekey('" + a + "','" + b + "');
      

  3.   

    修改js方法
     function rekey(num,name) 

    if(num!="")
                document.getElementById("txtNum").value=num;
    if(name!="") 
                document.getElementById("txtName").value=name ;
    }
      

  4.   

    �Բ��� 
    �����ҵı����е������
    ������Ϊ��ʱ  �Ҳ����ı�����ʾ  &nbsp   ������ʲô������ʾ������Ϊ�յ�����
      

  5.   

    怎么乱码啊
    就是当数据为空的时候 ,则调用方法时会显示&nbsp  现在就是不让显示&nbsp ,怎么解决
      

  6.   

    e.Row.Attributes.Add("onclick", "rekey('" + e.Row.Cells[0].Text.Replace(" ","") + "','" + e.Row.Cells[1].Text.Replace(" ","") + "');
      

  7.   

    function rekey(num,name) 

    if(num!=""&&num!=&nbsp) 
                document.getElementById("txtNum").value=num; 
    if(name!=""name!=&nbsp) 
                document.getElementById("txtName").value=name ; 
    }