Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

asp.net gridview and radio button

Posted on 2007-12-06
11
Medium Priority
?
7,872 Views
Last Modified: 2013-11-07
I created GridView Control and want to add radio button in the template. the UI is working, but I have two problems.

1. Let say it have 5 rows from the gridview, and I can select all 5 radio buttons...it is supposed to be one selected only
2. I want the radio button to carry two value. Is it possible? and how to do that?

I am beginner. please code me as clear as possible. 500pts here. this is c# asp.net 2.0
0
Comment
Question by:riskyricky1972
[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
11 Comments
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 20424284
Put this in your Columns section of the GridView.   Then when you do a postback you would access the selected field with Request.Form["Employee"]
<Columns>
 
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
 
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
 
<asp:TemplateField HeaderText="Select">
 
<ItemTemplate>
 
<input name="Employee" type="radio" value='<%# Eval("EmpID") %>' />
 
</ItemTemplate>
 
</asp:TemplateField>
 
</Columns>

Open in new window

0
 

Author Comment

by:riskyricky1972
ID: 20424554
I want asp.net control, not html. I will have to carry this value to mulitple pages...It does not work
0
 
LVL 10

Expert Comment

by:digitalZo
ID: 20425699
Add a groupname to those radiobuttons where you want only one value selected:

I didn't understand your 2nd question. Can you elaborate on it?

<asp:TemplateField HeaderText="Select">
 
<ItemTemplate>
 
<asp:RadioButton id="RadioButton1" runat="server" GroupName="MyGroup"></asp:RadioButton>
<asp:RadioButton id="RadioButton2" runat="server" GroupName="MyGroup"></asp:RadioButton>
<asp:RadioButton id="RadioButton3" runat="server" GroupName="MyGroup"></asp:RadioButton>
<asp:RadioButton id="RadioButton4" runat="server" GroupName="MyGroup"></asp:RadioButton>
<asp:RadioButton id="RadioButton5" runat="server" GroupName="MyGroup"></asp:RadioButton>
 
</ItemTemplate>
 
</asp:TemplateField>

Open in new window

0
Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 20426109

<asp:TemplateField HeaderText="Select">
 
<ItemTemplate>
 
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
            <asp:ListItem Value="1">1</asp:ListItem>
            <asp:ListItem Value="2">2</asp:ListItem>
            <asp:ListItem Value="3">3</asp:ListItem>
        </asp:RadioButtonList>
</ItemTemplate>
 
</asp:TemplateField>

Open in new window

0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 20428903
Correct me if I'm wrong, but I think he only wants one radio button per row and I can't think of any way to do that with an asp.net control.
0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 20428925
Using HTML controls you can save the result of the radio button to an hidden field or session variable, so it can be used later in another page.  If that works let me know and I can show you how.
0
 

Author Comment

by:riskyricky1972
ID: 20450890
CtrlAltDl: Show me how pls
0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 20454165

// This code is in the same page (or code behind) as your radio buttons
if (IsPostBack)
{
    //Save to a session variable
    Session["Employee"] = Request.Form["Employee"];
}
 
 
//This code is added to any page that needs to access the session variable
 
//Change the text label to use our radio button session variable
Label1.Text = Session["Employee"];

Open in new window

0
 
LVL 14

Accepted Solution

by:
CtrlAltDl earned 2000 total points
ID: 20454182
Here is some documentation on Session variables:
http://msdn2.microsoft.com/en-us/library/87069683.aspx
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20952969
Forced accept.

Computer101
Community Support Moderator
0

Featured Post

AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

688 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