JS给datagrid的单元格赋值
现在我想用js给datagrid的单元格赋值,
比如datagrid里面有10行数据,我想修改第10行的第一列,是纯数字的code,但是现在要求code的位数一直是4位,比如我输入12,显示的必须是0012,从12到0012我想用js来完成,但不知道怎么做,求高人指点!
<script type="text/javascript">
function SubjectGrid_AfterCellUpdateHandler(gridName, id)
{
var row = igtbl_getActiveRow("<%=SubjectGrid.ClientID %>");
var cell=row.getCellFromKey( "SubjectCode");
var flag=cell.getValue();
if(flag!=""&&flag!=null)
{
for (var i = 0; i < flag.length; i++)
{
var code = flag.substring(i,i+1);
if(! (code == "1" || code == "2" || code == "3" || code == "4" || code == "5" || code == "6" || code == "7" || code == "8" || code == "9" || code == "0"))
{
var cell=row.getCellFromKey( "SubjectCode");
cell.innerText= "";
var myForm = document.getElementById("aspnetForm");
myForm.submit();
return;
}
}
var temp = flag.length;
if(temp!=4)
{
for (var i = 0; i < 4 - temp; i++)
{
flag = "0" + flag;
}
var cell=row.getCellFromKey( "SubjectCode");
cell.innerText= flag;
var myForm = document.getElementById("aspnetForm");
myForm.submit();
}
}
}
</script>
这是我写得,在提交前能够获得正确的值(0012)但是无法赋给单元格!
------解决方案--------------------
私信之