Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using Radio buttons across multiple columns in GridView

Posted on 2010-01-04
9
Medium Priority
?
1,233 Views
Last Modified: 2013-12-17
Hi there

I have a table, that contains a number of rows, in each row there are three columns that are mutually exclusive.

What I need is to be able to have radio buttons that are linked across the three columns.
tocid       mandactionid       action       yes       no       notapp       comment
1       1       Action 1       1       0       0       Comment 1
1       2       Action 2       0       1       0       Comment 2
1       3       Action 3       1       0       0       Comment 3

I'd like for where there is a 1 for it to display a checked radio button, and where there is a 0 for it to be unchecked. This can then be edited by clicking the radio in another column where necessary.


Apologies if this is a little vague, I'm just beginning! Happy to post more detail if required.
0
Comment
Question by:k1ss0ff
  • 4
  • 3
  • 2
9 Comments
 
LVL 14

Expert Comment

by:amar31282
ID: 26170941
hmm
try this

in grid view add three radio buttons for the three columns and set there group names as

radiobutton1 groupname='<%# "group" + Eval("mandactionid")%>'

where i suppose mandactionid  is different for each row.


in this way all the three radio buttons will have same group name and you can select only one of them...

Regards,
amarjit
0
 
LVL 14

Assisted Solution

by:amar31282
amar31282 earned 400 total points
ID: 26170975
sorry missed some code

 yes                                                                                                                               no                                                                                                                          notapp
================================================================================================================================================
radiobutton1 groupname='<%# "group" + Eval("mandactionid")%>'          radiobutton2 groupname='<%# "group" + Eval("mandactionid")%>'        radiobutton2 groupname='<%# "group" + Eval("mandactionid")%>'


0
 

Author Comment

by:k1ss0ff
ID: 26171224
I'm having some trouble getting it to accept a radio button at all.  I've attached the code so far...
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" Debug="true" %>

<%@ Register assembly="System.Web.DynamicData, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.DynamicData" tagprefix="cc1" %>

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    <p>
        &nbsp;</p>
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
        DataSourceID="TOCIDs" DataTextField="tocname" DataValueField="tocid">
    </asp:DropDownList>
    <asp:ObjectDataSource ID="TOCIDs" runat="server" 
        OldValuesParameterFormatString="original_{0}" SelectMethod="GetTOCIDs" 
        TypeName="atTableAdapters.TOCIDsTableAdapter"></asp:ObjectDataSource>
    
    <br />
    
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataSourceID="MandatoryAnswersData">
        <Columns>
            <asp:BoundField DataField="tocid" HeaderText="tocid" SortExpression="tocid" />
            <asp:BoundField DataField="mandactionid" HeaderText="mandactionid" 
                SortExpression="mandactionid" />
            <asp:BoundField DataField="action" HeaderText="action" 
                SortExpression="action" />
            <asp:TemplateField HeaderText="yes" SortExpression="yes">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("yes") %>'></asp:Label>
                    <asp:RadioButton ID="RadioButton1" runat="server" 
                        Enabled='<%# Eval("yes") %>' />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="no" HeaderText="no" SortExpression="no" />
            <asp:BoundField DataField="notapp" HeaderText="notapp" 
                SortExpression="notapp" />
            <asp:BoundField DataField="comment" HeaderText="comment" 
                SortExpression="comment" />
        </Columns>
    </asp:GridView>
    <EditItemTemplate >

                    <br />
                         
            </EditItemTemplate>

    <asp:ObjectDataSource ID="MandatoryAnswersData" runat="server" 
        OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" 
        TypeName="atTableAdapters.MandatoryAnswersTableAdapter">
        <SelectParameters>
            <asp:ControlParameter ControlID="DropDownList1" Name="tocid" 
                PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>
    </form>
</body>
</html>

Open in new window

0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 16

Accepted Solution

by:
sunithnair earned 1600 total points
ID: 26171320
Try it this way
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
            <Columns>
                <asp:BoundField DataField="tocid" HeaderText="tocid" />
                <asp:BoundField DataField="mandactionid" HeaderText="mandactionid" />
                <asp:BoundField DataField="action" HeaderText="action" />
                <asp:TemplateField HeaderText="yes">
                    <ItemTemplate>
                        <asp:RadioButton ID="rdYes" runat="server" GroupName="RGroup" Checked='<%#Eval("yes")%>' />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="no">
                    <ItemTemplate>
                        <asp:RadioButton ID="rdNo" runat="server" GroupName="RGroup" Checked='<%#Eval("no")%>' />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="notapp">
                    <ItemTemplate>
                        <asp:RadioButton ID="rdNotApp" runat="server" GroupName="RGroup" Checked='<%#Eval("notapp")%>' />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="comment" HeaderText="comment" />
            </Columns>
        </asp:GridView>

Open in new window

0
 
LVL 14

Expert Comment

by:amar31282
ID: 26171328
you should have mentioned error also :)
0
 

Author Comment

by:k1ss0ff
ID: 26171414
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Getting there.  This is the error:

Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:

Line 33:                 <asp:TemplateField HeaderText="yes">
Line 34:                     <ItemTemplate>
Line 35:                         <asp:RadioButton ID="rdYes" runat="server" GroupName="RGroup" Checked='<%#Eval("yes")%>' />
Line 36:                     </ItemTemplate>
Line 37:                 </asp:TemplateField>


The yes / no / notapp fields are currently tinyint(3) - do they need to be changed to something that's yes or no/true or false ?
0
 
LVL 16

Assisted Solution

by:sunithnair
sunithnair earned 1600 total points
ID: 26171449
They should be of type boolean or you need to convert it like this
<asp:RadioButton ID="rdYes" runat="server" GroupName="RGroup" Checked='<%#Convert.ToBoolean(Eval("yes"))%>' />

Open in new window

0
 

Author Comment

by:k1ss0ff
ID: 26171537
Yay, fixed, many thanks :)
0
 

Author Closing Comment

by:k1ss0ff
ID: 31672363
Very helpful, many thanks for being patient!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month21 days, 7 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question