JavaScript 传值
有一个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就变成“ ”了,
除了下面这么办 还有其他方法吗,我的GridView列很多的下面这样写很费时间的。
function jsFunctionName(a1,a2)//类别 名称 规格
{ var str1=a1;var str2=a2;
if(str1!=" "){
window.document.getElementById("txtA").value=str1;}
if(str2!=" "){
window.document.getElementById("txtB").value=str2;}
}