I have a GridView, I want to find the Value of a Control based on its id at Client Side using javascript. I have the index of row which I'm clicking. Now I want to find the Value of a Column which has a label in same row.
function OnClientClickReplaceRewardRuleFile(link) {
var row = link.parentNode.parentNode;
var rowIndex = row.rowIndex - 1;
// alert("RowIndex: " + rowIndex);
var lbl = document.getElementById('<%=GridViewMultiplePOSAssociationId.Rows[rowIndex].FindControl("LabelStatusPendingPOSId").ClientID %>');
alert(lbl);
return false;
}
Its not working.
aspx code.
<asp:TemplateField HeaderStyle-Width="80px" ItemStyle-Width="250px" ItemStyle-HorizontalAlign="Center"
HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="HyperLinkAssociate" CommandArgument='<%#Eval("POS Id") %>'
CommandName="Associate" Text="Associate" runat="server" OnClientClick="return OnClientClickAssociateRewardRuleFile(this);" CausesValidation="false"></asp:LinkButton>/<asp:LinkButton
ID="HyperLinkReplace" CommandArgument='<%#Eval("POS Id") %>' CommandName="Replace"
Text="Replace" runat="server" OnClientClick="return OnClientClickReplaceRewardRuleFile(this);" CausesValidation="false"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField >
I have tried this:
function OnClientClickReplaceRewardRuleFile(link) {
var row = link.parentNode.parentNode;
var rowIndex = row.rowIndex - 1;
var table = document.getElementById('<%=GridViewMultiplePOSAssociationId.ClientID %>');
var lbls = document.getElementsByTagName('label');
var spans = document.getElementsByTagName('span');
for (var i = 0; i < lbls.length; i++) {
if (lbls[i].id.indexOf('LabelStatusPendingPOSId') > 0) {
if (rowIndex == i) {
if (lbls[i].innerText == 'Applied') {
alert('Action cannot be completed for this POS.');
return false;
}
break;
}
}
}
for (var i = 0; i < spans.length; i++) {
if (spans[i].id.indexOf('LabelStatusPendingPOSId') > 0) {
if (rowIndex == i) {
if (spans[i].innerText == 'Applied') {
alert('Action cannot be completed for this POS.');
return false;
}
break;
}
}
}
}
Try this
function OnClientClickReplaceRewardRuleFile(link) {
var row = link.parentNode.parentNode;
var table = document.getElementById('<%=GridView1.ClientID %>');
var lbls = document.getElementsByTagName('label');
var spans = document.getElementsByTagName('span');
for (var i = 0; i < lbls.length; i++) {
if (lbls[i].id.indexOf('LabelStatusPendingPOSId') > 0) {
alert(lbls[i]);
break;
}
}
for (var i = 0; i < spans.length; i++) {
if (spans[i].id.indexOf('LabelStatusPendingPOSId') > 0) {
alert(spans[i]);
break;
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.