Gridview Footer row textbox in JavaScript

2019-04-17 01:08发布

问题:

I have been accessing the rows of Gridview quite easily using javascript. But when I try to add a new row and then try to access, then the code is not working. Is there a way by which I can access the footer row text box?

Below is my code which works well when edit mode text boxes are to be accessed. Please donot post any link.

function OnSelectIndexChange() {
        var drpdwn = document.getElementById("ddlSelectUnderwriterCond");
        var drpdwnValue = drpdwn.options[drpdwn.selectedIndex].text;
        var gridview = document.getElementById("<%= StandardUndewritingGrid.ClientID %>");
        for (var i = 1; i <= gridview.rows.length; i++) {
            var labels = gridview.rows[i].cells[0].getElementsByTagName("input")[0].value;
            var txtbx = gridview.rows[i].cells[0].children[0];
            if (drpdwnValue != '-- Select --')
                txtbx.value = labels + '<^>' + drpdwnValue + '<^>';
        }
    }

回答1:

I have just figured out a way of accessing the footer row and code is working fine so I am posting as it might help someone as well:

var flabels = document.getElementById('<%=((TextBox)gridname.FooterRow.FindControl("controlname")).ClientID %>');
 if (flabels != null) {
 }


回答2:

It works by simple logic:

var grid = document.getElementById('<%= GridviewName.ClientID %>');
var FooterTextBoxName = grid.getElementsbyTagName('FooterTextBoxName');