Click here to Skip to main content
15,897,032 members
Articles / Web Development / ASP.NET

Grouped Radio Buttons in Gridview

Rate me:
Please Sign up or sign in to vote.
4.69/5 (8 votes)
28 Sep 2010CPOL2 min read 116.8K   2.2K   17  
Radio buttons in Gridview without JavaScript
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="radiobutton_in_gridview._Default" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
            
             <asp:Panel ID="Panel11" runat="server" CssClass="dropShadowPanel">
            <div style="padding:10px">  
                <asp:Label ID="Label_limit" runat="server" Text="Label"></asp:Label>
                <hr />
           
                <asp:Panel ID="CollapseHeader" runat="server" style="cursor: pointer;">
                    <asp:Label ID="Label_detail" runat="server" Text="Label">Show Details...</asp:Label>
                </asp:Panel>
                <asp:Panel ID="Panel22" runat="server" style="overflow:hidden;height:0"> 
                   
                    </asp:Panel>
                <asp:CollapsiblePanelExtender ID="cpe1" runat="Server"
                    TargetControlID="Panel22"
                    Collapsed="true"
                    CollapsedText="Show Details..."
                    ExpandedText="Hide Details"
                    TextLabelID="Label_detail"
                    ExpandControlID="CollapseHeader"
                    CollapseControlID="CollapseHeader"
                    SuppressPostBack="true" ExpandDirection="Horizontal" />
            </div>
        </asp:Panel>

                <asp:AlwaysVisibleControlExtender ID="Panel1_AlwaysVisibleControlExtender" 
                    runat="server" Enabled="True" HorizontalSide="Right" TargetControlID="Panel11" 
                    VerticalSide="Middle">
                </asp:AlwaysVisibleControlExtender>

        <asp:DropShadowExtender ID="DropShadowExtender1" runat="server"
            BehaviorID="DropShadowBehavior1"
            TargetControlID="Panel11"
            Width="5"
            Rounded="true"
            Radius="6"
            Opacity=".75"
            TrackPosition="true" />
            
            
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
    SelectCommand="SELECT * FROM [Employees]"></asp:SqlDataSource>
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                    DataKeyNames="EmployeeID" DataSourceID="SqlDataSource1" Font-Names="Verdana" 
                    Font-Size="14px" Width="289px">
                    <Columns>
                        <asp:BoundField DataField="LastName" HeaderText="LastName" 
                            SortExpression="LastName" />
                        <asp:BoundField DataField="FirstName" HeaderText="FirstName" 
                            SortExpression="FirstName" />
                        <asp:TemplateField HeaderText="Useless Group">
                            <ItemTemplate>
                                    <asp:RadioButton ID="MyRadioButton" runat="server" 
                                        GroupName="UselessGroup"  />
                            </ItemTemplate>
                        </asp:TemplateField>
                       
                        <asp:TemplateField HeaderText="Fake group">
                            <ItemTemplate>
                                <asp:RadioButton ID="MyRadioButton1" runat="server" 
                                        GroupName="FakeGroup"  AutoPostBack="True" OnCheckedChanged="MyRadioButton1_CheckedChanged" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        
                        <asp:TemplateField HeaderText="EmployeeID" Visible="False">
                        <ItemTemplate>
                            <asp:Label ID="lblemployeeid" runat="server" Text='<%# Eval("employeeID") %>' />
                                
                        </ItemTemplate>
                 </asp:TemplateField>
                    </Columns>
                    <AlternatingRowStyle BackColor="#EEF1F5" />
                </asp:GridView>
                <br />
                <asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="True" 
                    Text="RB outside the gridview" />
                    
                    
                    
                   
            
            
            
        
    
                <br />
                
                    
                    
                    
                   
            
            
            
        
    
            </ContentTemplate>
        </asp:UpdatePanel>
    
    </div>
    </form>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Web Developer
New Zealand New Zealand
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions