首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

动态往table中添加行,行的对应列中含有DropDownList 服务器控件,如何绑定数据到该控件

2013-10-10 
动态往table中添加行,行的对应列中含有DropDownList 服务器控件,怎么绑定数据到该控件ASP.NET+c#代码如下:

动态往table中添加行,行的对应列中含有DropDownList 服务器控件,怎么绑定数据到该控件
ASP.NET+c#
代码如下:  
实现动态添加行的JS代码如下

        function addRow(tabObj, colNum, targPos) {
            var sorPos = parseInt("<%=GetLinCount()%>") + 4;
            var IDTab = String(sorPos);
            var nTR = tabObj.insertRow(tabObj.rows.length - targPos); 
            var TRs = tabObj.getElementsByTagName('tr'); // Get TRs collection from the appointed table 
            var sorTR = TRs[sorPos];                     // Positioned the sorTR 
            var TDs = sorTR.getElementsByTagName('td');     
            if (colNum == 0 || colNum == undefined || colNum == isNaN) {
                colNum = tabObj.rows[4].cells.length;
            }
            var ntd = new Array();                       // Create a new TDs array 
            for (var i = 0; i < colNum; i++) {
                ntd[i] = nTR.insertCell();
                if (0 == i) {
                    ntd[i].style.cssText = "BORDER-TOP:  #168bd9   2px   solid;BACKGROUND-COLOR: #168bd9";
                }
                else {
                    if (1 == i) {
                        ntd[i].id = "name" + IDTab;
                        
                    }
                    if (2 == i) {
                        ntd[i].id = "version" + IDTab;
                    }
                }
                ntd[i].innerHTML = TDs[i].innerHTML;     // copy the value in ntd[i]'s innerHTML from corresponding TDs

            }
        }
        function deleteRow(tabObj,btnObj) {    //Remove table row 
            var targPos = parseInt("<%=GetLinCount()%>") + 4;
            for (var i = 0; i < tabObj.rows.length; i++) {
                if (tabObj.getElementsByTagName('label')[i] == btnObj) {
                    tabObj.deleteRow(i + targPos);
                }
            }

        }
  

对应添加行的.aspx代码如下

            <tr id="AddNewRow" style="display:none;">
                <td id="FirstId" style="background-color:#168bd9;border-top:none;"></td>


                <td><asp:DropDownList ID="AddName_DDList" runat="server" Width="100%"></asp:DropDownList></td>
                <td><asp:DropDownList ID="AddVersion_DDList" runat="server" Width="100%"></asp:DropDownList></td>
                <td><label><asp:Button ID="AddDelete_Button" runat="server" Width="100px" Text="Delete" OnClick="AddDelete_Button_Click" OnClientClick="return deleteRow(document.all.tabUserInfo, this.parentNode)" /></label></td>
            </tr>



现在我想往生成的DropDownList 中绑定数据库数据该怎么实现呢?谢谢了!希望详细点 这方面知识比较欠缺。最好给一个相关的例子 参考一下。

http://www.cnblogs.com/insus/archive/2011/12/01/2270455.html

热点排行