首页 > 技术文章 > gridview根据数据中的数据动态添加控件

lei51211 2013-12-31 13:44 原文

//根据数据中的数据动态添加控件
function AddRow()
{
    if(xmlHttp==null)
    {
        creatXhttp();
    }
    xmlHttp.open("get","Apply.aspx?type=1",true);
    xmlHttp.onReadyStateChange=function ()
    {
        if(xmlHttp.readyState==4)
        {
            types=xmlHttp.responseText.split(',');
            var table = document.getElementById("tbNewProduct");

            var row = document.createElement("tr");
            var cellName = document.createElement("td");
            var cellCount = document.createElement("td");
            var cellPrice = document.createElement("td");
            var cellTotal = document.createElement("td");
            var cellDesc = document.createElement("td");
            var button = document.createElement("td");
            
            
            var select = document.createElement('select');
            var Count = document.createElement('input');
            var Price = document.createElement('input');
            var Total = document.createElement('input');
            var Desc = document.createElement('input');
            var btnDel = document.createElement('input');
            var option = document.createElement('option');
            option.innerHTML = "请选择";
            
           // option.setAttribute
            select.setAttribute("id","select");
            select.onchange = function(){GetPrice(row)};
            
            select.appendChild(option);
            Count.setAttribute("id","count");
            Count.setAttribute("type","text");
            Count.onblur = function(){GetSubprice(row)};
            
            Price.setAttribute("id","price");
            Price.setAttribute("type","text");
            Price.setAttribute("class","textbox");
            Price.setAttribute("disabled","disabled");
            
            Total.setAttribute("id","total");
            Total.setAttribute("type","text");
            Total.setAttribute("disabled","disabled");
        
            Desc.setAttribute("id","total");
            Desc.setAttribute("type","text");
         
            btnDel.setAttribute("type","button");
            btnDel.setAttribute("id","btnDel");
            btnDel.setAttribute("value","删除");
           
            btnDel.onclick = function(){ deleteRow()};
            
            for(var i=0;i<types.length-1;i+=3)
            {
                var option = document.createElement("option");
                option.value= types[i];
                option.innerHTML = types[i+1];
                select.appendChild(option);
            }
            
            cellName.appendChild(select);
            cellCount.appendChild(Count);
            cellPrice.appendChild(Price);
            cellTotal.appendChild(Total);
            cellDesc.appendChild(Desc);
            button.appendChild(btnDel);
            
            row.appendChild(cellName);
            row.appendChild(cellCount); 
            row.appendChild(cellPrice); 
            row.appendChild(cellTotal);
            row.appendChild(cellDesc);
            row.appendChild(button);
            table.appendChild(row);
        }
    }
    xmlHttp.send(null);
}

 

推荐阅读