473,511 Members | 17,486 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 4256
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 programmatically.

--
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:TemplateField>
<ItemTemplate>
<asp:Literal id="ltrl" runat="server" />
</ItemTemplate>
</asp:TemplateField>

then you would want to handle RowCreated event as follows:

private object _selectedKey = null;

private void grd_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TableCell cell = e.Row.Cells[0];
string name = grd.ClientID + "$" + "rbo";
Literal ltrl = (Literal)cell.Controls[1];
int index = e.Row.RowIndex;
string id = name.Replace("$", "_") + "_" + index.ToString();
bool isSelected = this.IsPostBack && this.Request.Form[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 programmatically.

--
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
1145
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...
0
1178
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...
3
1916
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...
3
1344
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...
5
9414
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...
3
1644
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:...
0
1018
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...
7
22390
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...
1
2941
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....
0
7245
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,...
0
7356
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,...
0
7427
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...
0
7512
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...
0
5671
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3227
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...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
449
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.