Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working on a page which has a master page. I have a gridview in the page and inside it I am dynamically populating radio buttons. OnClick event of radio button I am calling a javascript function which is in some other file.

ASP.NET
<asp:GridView AutoGenerateColumns="False" AllowSorting="false" Width="100%" ID="List" runat="server" AllowPaging="false" GridLines="None" ShowHeader="False">
<Columns>
<asp:TemplateField ItemStyle-HorizontalAlign="Left">                                         
<ItemTemplate>
<asp:RadioButton ID="Criteria" Width="1px" runat="server" GroupName="SelectCriteria" onclick="javascript:ValidateMultipleCheck(this,'CPH_List');" />
<asp:HiddenField ID="hdn" runat="server" Value='<%# DataBinder.Eval (Container.DataItem, "Key") %>' />>'

</ItemTemplate>
</asp:TemplateField>

<asp:BoundField DataField="Value" ItemStyle-HorizontalAlign="Left" />
</Columns>
</asp:GridView>


JavaScript
function ValidateMultipleCheck(control, gridName) {
    var controlId = control.id;
    var Parent = document.getElementById(gridName);
    for (i = 0; i < Parent.rows.length; i++) {
        var tr = Parent.rows[i];
        var td = tr.childNodes[0].childNodes[0];
        var item = td.firstChild;
        if (item != null && item.id != controlId && item.type == "radio") {
            if (item.checked) {
                item.checked = false;
            }
        }
    }
}


While I click on the radio buttons, in the javascript function, though I am getting the values passed correctly but the var Parent's value is showing as {...} and later terminating the execution as unable to get firstchild for undefined or null node.

Please let me know what I am missing here.
Posted
Comments
Dilan Shaminda 22-Jul-14 9:35am    
Your GridView ID is "List" but you are passing "CPH_List" as the GridView ID to your javascript funtion
Member 10963037 23-Jul-14 2:41am    
I am passing gridview id as CPH_List as it is coming in view source of the page.
Sulabh Agarwal 23-Jul-14 5:40am    
try to use this..
javascript:ValidateMultipleCheck(this,'<%= CPH_List.ClientID %>');"

1 solution

To check the grid view Client id use can write

Response.Write(List.ClientID);
on aspx page load , after getting that id,
pass it in place of 'CPH_List'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900