473,322 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

radio button list question

how can i disable a specific button in a list that is bound to an object
(datasource)? I can, it seems disable a button that's added manuelly.

Any help appreciated,
thanks
--
Share The Knowledge. I need all the help I can get and so do you!
Aug 29 '08 #1
2 1196
Hi Yankee,

You should be able to check a property during the list's DataBound event and
then disable an item based on the value.

Here's the idea:

protected void RadioButtonList1_DataBound(object sender, EventArgs e)
{
foreach (ListItem li in RadioButtonList1.Items)
{
li.Enabled = (bool)(li.Value.Contains(".ca"));
}
}

Full code below.

Ken

using System;
using System.Collections.Generic;
using System.Web;

/// <summary>
/// Summary description for datacollection
/// </summary>
public class datacollection
{

public List<stringGetDataCollection()
{
List<stringsites = new List<string>();
sites.Add("www.kencox.ca");
sites.Add("www.microsoft.com");
sites.Add("www.asp.net");
return sites;

}
}
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void RadioButtonList1_DataBound(object sender, EventArgs e)
{
foreach (ListItem li in RadioButtonList1.Items)
{
li.Enabled = (bool)(li.Value.Contains(".ca"));
}
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
DataSourceID="ObjectDataSource1"
OnDataBound="RadioButtonList1_DataBound">
</asp:RadioButtonList>
</div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetDataCollection"
TypeName="datacollection"></asp:ObjectDataSource>
</form>
</body>
</html>
"Yankee Imperialist Dog" <Ya******************@discussions.microsoft.com>
wrote in message news:D8**********************************@microsof t.com...
how can i disable a specific button in a list that is bound to an object
(datasource)? I can, it seems disable a button that's added manuelly.

Any help appreciated,
thanks
--
Share The Knowledge. I need all the help I can get and so do you!

Aug 29 '08 #2
I appreciate your response. I thought of that but the data value i need is
gone at that point.

is there a way to check the data source for a boolean? i can run the
collection as you suggested but the data source is done at that point. I
could concat a value then remove it using your method, but i was hoping for a
cleaner way to do it.

no other way?

--
Share The Knowledge. I need all the help I can get and so do you!
"Ken Cox [MVP]" wrote:
Hi Yankee,

You should be able to check a property during the list's DataBound event and
then disable an item based on the value.

Here's the idea:

protected void RadioButtonList1_DataBound(object sender, EventArgs e)
{
foreach (ListItem li in RadioButtonList1.Items)
{
li.Enabled = (bool)(li.Value.Contains(".ca"));
}
}

Full code below.

Ken

using System;
using System.Collections.Generic;
using System.Web;

/// <summary>
/// Summary description for datacollection
/// </summary>
public class datacollection
{

public List<stringGetDataCollection()
{
List<stringsites = new List<string>();
sites.Add("www.kencox.ca");
sites.Add("www.microsoft.com");
sites.Add("www.asp.net");
return sites;

}
}
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void RadioButtonList1_DataBound(object sender, EventArgs e)
{
foreach (ListItem li in RadioButtonList1.Items)
{
li.Enabled = (bool)(li.Value.Contains(".ca"));
}
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
DataSourceID="ObjectDataSource1"
OnDataBound="RadioButtonList1_DataBound">
</asp:RadioButtonList>
</div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetDataCollection"
TypeName="datacollection"></asp:ObjectDataSource>
</form>
</body>
</html>
"Yankee Imperialist Dog" <Ya******************@discussions.microsoft.com>
wrote in message news:D8**********************************@microsof t.com...
how can i disable a specific button in a list that is bound to an object
(datasource)? I can, it seems disable a button that's added manuelly.

Any help appreciated,
thanks
--
Share The Knowledge. I need all the help I can get and so do you!


Aug 29 '08 #3

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

Similar topics

1
by: Matt | last post by:
The following code is try to validate if the user selects a radio button choice. I dont understand why document.UserInputs.question.value; gets undefined value even user make a choice. I tried...
1
by: Michael Albanese | last post by:
I am developing an application to handle my compay's OSHA reporting requirements. Some of the input criteria are technical and narowly defined, so I was trying to prvide what i call "Context...
1
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there...
14
by: Steve Chatham | last post by:
I have a combo box that gets populated with a group of items based on a sql table. I had in mind that I'd insert a value at the beginning of that combo box, that'd say "No Item Selected" and...
3
by: Ferret Face | last post by:
Hello, I have a web page that gets the user to select items from a list of options. This list is a set of independant Radio Buttons. I did not use a Radio Button List because I wanted the...
1
by: Jerry | last post by:
We have a 10-question quiz for kids, each question being a yes or no answer using radio selections. I'd like to keep a current total of yes's and no's at the bottom of the quiz (if the user selects...
1
by: Joe Attardi | last post by:
Hi all, On a form on one of my pages I have two <select> elements, and each one is paired up with a radio button. The idea is to choose an item from one list or the other and select the radio...
4
by: Blasting Cap | last post by:
I have a page that has a number of radio buttons that will be displayed to different access levels of a user who logs in to my website. For instance, if there are a dozen buttons, user1 will see...
4
by: CURTISLESPERANCE | last post by:
Hi, I am trying to figure out if this is possible. I need to display 4 radio buttons next to a question then 3 radio buttons after. The 2 different group radio buttons and questions are coming from...
6
by: dba | last post by:
using the following code with a problem.... echo "<input type='hidden' name='member_id' value=\"{$row}\">{$row}"; echo "<input type='radio' name='member_name' value=\"{$row}\">{$row}<br />"; ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.