Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# ASP.NET Radio buttons I need unique rows AND columns (web app)

Posted on 2009-05-20
5
Medium Priority
?
269 Views
Last Modified: 2013-12-17
C# + ASP.NET web application. Need unique rows and coumns for radio buttons.

I have tried everything from google to tinkering - no luck. I have a 7 by 7 grid of radio buttons. Across the columns are the days of the week. Across the rows (side) are labels. I need for the user to only be able to select one entry per day and one entry ONLY per row.

Using GroupName="Monday" I can easily set a column OR row to only accept one radio button selection but how do I also get both row and column it to only select one?

Help please.

Thanks!
KarlS2010
0
Comment
Question by:KarlS2010
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 26

Assisted Solution

by:Anurag Thakur
Anurag Thakur earned 800 total points
ID: 24433872
to achieve the functionality you will have to create a work around and there is no direct solution available
the approach what i will suggest set the groupname property but along with that you will have to add a customvalidator control and then manually loop around a set of radio buttons to see if more than one is selected and if yes then thow an error
0
 

Author Comment

by:KarlS2010
ID: 24433917
I was afraid of that - anyone think of anything else? (thanks raq)
0
 

Author Comment

by:KarlS2010
ID: 24434025
What if this were being done in a Windows Form?
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24434174
its logically not possible even in windows forms (havent worked much in win forms though)
0
 
LVL 12

Accepted Solution

by:
wht1986 earned 1200 total points
ID: 24434366
Below is a quick code behind solution.  Notice all the RadioButtons hav an ID in the format of

"RadioButton" + the row number + the column number

They all go to the same check changed event. I put mine inside an update panel as well.
<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <table>
                <tr>
                    <th>Label</th>
                    <th>Sunday</th>
                    <th>Monday</th>
                    <th>Tuesday</th>
                    <th>Wednesday</th>
                    <th>Thursday</th>
                    <th>Friday</th>
                    <th>Saturday</th>
                </tr>
                <tr>
                    <td><asp:Label ID="Label1" Text="Label1" runat="server" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton11" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton12" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton13" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton14" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton15" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton16" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton17" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                </tr>
                <tr>
                    <td><asp:Label ID="Label2" Text="Label2" runat="server" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton21" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton22" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton23" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton24" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton25" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton26" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton27" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                </tr>
                <tr>
                    <td><asp:Label ID="Label3" Text="Label3" runat="server" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton31" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton32" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton33" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton34" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton35" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton36" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton37" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                </tr>
                <tr>
                    <td><asp:Label ID="Label4" Text="Label4" runat="server" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton41" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton42" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton43" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton44" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton45" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton46" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton47" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                </tr>
                <tr>
                    <td><asp:Label ID="Label5" Text="Label5" runat="server" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton51" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton52" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton53" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton54" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton55" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton56" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton57" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                </tr>
                <tr>
                    <td><asp:Label ID="Label6" Text="Label6" runat="server" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton61" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton62" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton63" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton64" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton65" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton66" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton67" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                </tr>
                <tr>
                    <td><asp:Label ID="Label7" Text="Label7" runat="server" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton71" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton72" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton73" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton74" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton75" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton76" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                    <td align="center"><asp:RadioButton ID="RadioButton77" runat="server" oncheckedchanged="RadioButton_CheckedChanged" AutoPostBack="true" /></td>
                </tr>
            </table>
        </ContentTemplate>
    </asp:UpdatePanel>
</form>
 
=========================================================
 
public partial class _Default : System.Web.UI.Page 
{
 
    protected void RadioButton_CheckedChanged(object sender, EventArgs e)
    {
        RadioButton rb = (RadioButton)sender;
 
        int rbRow = int.Parse(rb.ID.Substring(11, 1));
        int rbCol = int.Parse(rb.ID.Substring(12, 1));
 
        for (int col = 1; col < 8; col++)
        {
            rb = (RadioButton)FindControl("RadioButton" + rbRow.ToString() + col.ToString());
            rb.Checked = (rbCol == col);
        }
 
        for (int row = 1; row < 8; row++)
        {
            rb = (RadioButton)FindControl("RadioButton" + row.ToString() + rbCol.ToString());
            rb.Checked = (rbRow == row);
        }
 
    }
}

Open in new window

0

Featured Post

Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

730 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