473,587 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Client side radiobutton selection

Hi Guys,

I have a gridview and the first column is a template that generate a
radiobuttons in the gridvew. and I would like that user will be able to
select one option from the list of the generated radio buttons in my first
column - in Client side. (as if in multiple choice exams)
Thanks.

--
Regards,
M.Rochdi
Jun 29 '07 #1
3 4262
Mike,

Just set GroupName property for your RadioButton inside the template - this
will ensure that only one can be selected

"Mike" wrote:
Hi Guys,

I have a gridview and the first column is a template that generate a
radiobuttons in the gridvew. and I would like that user will be able to
select one option from the list of the generated radio buttons in my first
column - in Client side. (as if in multiple choice exams)
Thanks.

--
Regards,
M.Rochdi
Jun 29 '07 #2
That was the first thing I did but It didn't work.
and that's why it has to be done programmaticall y.

--
Regards,
M.Rochdi
"Sergey Poberezovskiy" wrote:
Mike,

Just set GroupName property for your RadioButton inside the template - this
will ensure that only one can be selected

"Mike" wrote:
Hi Guys,

I have a gridview and the first column is a template that generate a
radiobuttons in the gridvew. and I would like that user will be able to
select one option from the list of the generated radio buttons in my first
column - in Client side. (as if in multiple choice exams)
Thanks.

--
Regards,
M.Rochdi
Jun 29 '07 #3
Mike,

It looks like you up to a bit of coding. Suppose your Template column is the
first in the grid and looks as follows:

<asp:TemplateFi eld>
<ItemTemplate >
<asp:Literal id="ltrl" runat="server" />
</ItemTemplate>
</asp:TemplateFie ld>

then you would want to handle RowCreated event as follows:

private object _selectedKey = null;

private void grd_RowCreated( object sender, GridViewRowEven tArgs e)
{
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
TableCell cell = e.Row.Cells[0];
string name = grd.ClientID + "$" + "rbo";
Literal ltrl = (Literal)cell.C ontrols[1];
int index = e.Row.RowIndex;
string id = name.Replace("$ ", "_") + "_" + index.ToString( );
bool isSelected = this.IsPostBack && this.Request.Fo rm[name] != null &&
int.Parse(this. Request.Form[name]) == index;
string selected = (isSelected) ? "checked" : "";
if (isSelected)
{
selectedKey = grd.DataKeys[index];
}
ltrl.Text = string.Format(" <input type='radio' id='{0}' name='{1}'
value='{2}' {3} />", id, name, index, selected);
}
}

Note that you can get the value of the selectedKey on your postback.

Hope this helps

"Mike" wrote:
That was the first thing I did but It didn't work.
and that's why it has to be done programmaticall y.

--
Regards,
M.Rochdi
"Sergey Poberezovskiy" wrote:
Mike,

Just set GroupName property for your RadioButton inside the template - this
will ensure that only one can be selected

"Mike" wrote:
Hi Guys,
>
I have a gridview and the first column is a template that generate a
radiobuttons in the gridvew. and I would like that user will be able to
select one option from the list of the generated radio buttons in my first
column - in Client side. (as if in multiple choice exams)
>
>
Thanks.
>
--
Regards,
M.Rochdi
Jun 29 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1149
by: Jerry Camel | last post by:
1. I can add a value to a listbox, but when the page posts back, I lose the items I added from client side script. (Items added in server script stay in the list.) I'm guessing it's a view state issue or something. How do I add items to a listbox on the client side and have them acknowledged by the viewstate process? 2. Is it possible to...
0
1182
by: Bidarkota | last post by:
I have a Datagrid and i need a functionality to set the row of a datagrid to a color(blue) when i click on the DataGrid row. I have a check box in the DataGrid Header if i select the checkbox all the rows in the datagrid are set with the color(blue) at client side. i wrote the code but it is giving problems. can you pls help me out in solving...
3
1919
by: UJ | last post by:
Can somebody help me please? I have two 'sets' of controls on a page. There are two radio buttons that enable the two sets (when radiobutton A is checked, set A should be enabled, B, Set B should be enabled). I know how to do it on the server side but not on the client side (I'd rather not have the page reload). Can somebody help me? I know...
3
1348
by: KathyMarriage | last post by:
Hello In days gone by I was a VB programmer but currently tasked to find some answers for a ASP guy. Basically I am wanting to incorporate some of the functionality of the Common Dialog control into this Web tool we are building, specifically the InitDir and FileType properties. The end user needs to select a file stored client-side -...
5
9419
by: Barry | last post by:
I've wasted the whole day trying things and researching, but nothing is working. I would *greatly* appreciate if someone can give me the solution to this problem. I'm using the .NET Framework 2.0 in C# with a Master page and additional .aspx pages with .cs code-behind pages in Windows XP. In an .aspx page I have declared a control as...
3
1649
by: Vinnie | last post by:
I placed the following code into my page, but i get an error message, why? The code is: if (this.RadioButtonContatto.Checked == "YES") The error message is: CS0117: 'System.Web.UI.WebControls.RadioButtonList' does not contain a definition for 'Checked'
0
1020
by: Nathan Sokalski | last post by:
I have written a Validator (a class that inherits from the BaseValidator class), and it includes client-side validation functions. The validator is a conditional validator that only validates if a specified checkbox, radiobutton, dropdownlist item, etc. is checked or selected. The only feature I have left to add is to hide the error message if...
7
22446
controlbox
by: controlbox | last post by:
I have recently inplemented some drop-down lists (combos) on a page where one is dynamically populated according to the selection of another using the microsoft ajax extensions. I had to set AutoPostBack = true, and enable viewstate in order for the serverside events to fire, but once this was done, all seemed well - so far so good... Also,...
1
2950
by: jmartmem | last post by:
Greetings, I have a nagging problem with client-side dynamic dependent list boxes that perhaps someone can help me troubleshoot. I have a form with a series of dynamic dependent list boxes. Making a selection from list/box A (Qtr) selects a fiscal quarter, which then refreshes the values in list/box B (Mth), which shows the 3 months in that...
0
7920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7973
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5394
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.