Click here to Skip to main content
15,920,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a grid view.

I have 100 rows

in each row i have radio button list.

how to validate whether radio button is selected in each row or not?
Posted
Comments
What have you tried and where is the problem?

hi Nanda kishore

Try this code..


XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">

        var validateradios = function () {

            var icount = 0;
            var grid = document.getElementById('<%=GridView1.ClientID %>');
            for (var i = 1; i < grid.rows.length; i++) {

                var row = grid.rows[i];
                var targetcell = row.cells[0];
                var inputs = targetcell.getElementsByTagName("input");

                for (var j = 0; j < inputs.length; j++)
                    if (inputs[j].checked) {
                        icount++; break;
                    }

            }

            if (icount == (grid.rows.length - 1))
                alert(' all rows checked');
            else
                alert('some rows need to be checked');

        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="validateradios(); return false;" />
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:RadioButtonList ID="rdb" runat="server">
                        <asp:ListItem Text="Apple"></asp:ListItem>
                        <asp:ListItem Text="Orange"></asp:ListItem>
                        <asp:ListItem Text="Grapes"></asp:ListItem>
                    </asp:RadioButtonList>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    </form>
</body>
</html>



Code Behind:

C#
protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack) { }
            {
                GridView1.DataSource = Enumerable.Range(0,3);
                GridView1.DataBind();
            }
        }
 
Share this answer
 
Comments
nandakishoreroyal 9-Dec-13 2:08am    
Hi karthik mahalingam01,

Thanq for ur great help,
It saved me lot of time..

Working very great..

thanks a lot...
Karthik_Mahalingam 9-Dec-13 3:15am    
welcome kishore, happy coding :)
 
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