Click here to Skip to main content
15,944,832 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
i have table:- code  : Name    :  Absence : Out   :  Vacation :  Date 
                             12144  : name1   :    true  : false :  false    : 28-8-2016
                             12111  : name2   :    False : false :  True     : 28-8-2016

i want create columns radio botton or checkbox but the user can't click more than one 
how i do that because i cant find radio button in gridview 


What I have tried:

i want know how i create radiobotton in the gridview?
Posted
Updated 18-Aug-16 20:25pm
Comments
MahmoudOmar 18-Aug-16 4:37am    
windows application not asp.net
Karthik_Mahalingam 18-Aug-16 4:39am    
gridview is used in asp.net where as datagridview in windows,
Please specify it in the question. so that the users will pay more attention to it.

If you are using GridView in WPF, you may add radio buttons to a data-bound column ("IsSelected") in this way:

XML
<listview itemssource="{Binding Items}">
            <listview.view>
                <gridview>
                    <gridviewcolumn header="Selected">
                        <gridviewcolumn.celltemplate>
                            <datatemplate>
                                <radiobutton ischecked="{Binding IsSelected}" groupname="IsSelected" />
                            </datatemplate>
                        </gridviewcolumn.celltemplate>
                    </gridviewcolumn>
                    <gridviewcolumn header="Name">
                      DisplayMemberBinding="{Binding Name}" />
                                    </gridviewcolumn></gridview>
            </listview.view>
        </listview>
 
Share this answer
 
ASP.NET
<asp:GridView ID="GridView1" runat="server"
HeaderStyle-BackColor = "green"
AutoGenerateColumns = "false" Font-Names = "Arial"
OnPageIndexChanging = "OnPaging"
Font-Size = "11pt" AlternatingRowStyle-BackColor = "#C2D69B"
AllowPaging = "true">
<Columns>
<asp:TemplateField>
<ItemTemplate>
    <asp:RadioButton ID="RadioButton1" runat="server"
        onclick = "RadioCheck(this);"/>
    <asp:HiddenField ID="HiddenField1" runat="server"
        Value = '<%#Eval("CustomerID")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ItemStyle-Width="150px" DataField="CustomerID"
    HeaderText="CustomerID"  />
<asp:BoundField ItemStyle-Width="150px" DataField="City"
    HeaderText="City" />
<asp:BoundField ItemStyle-Width="150px" DataField="PostalCode"
    HeaderText="PostalCode"/>
</Columns>
</asp:GridView>
 
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