By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,301 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,301 IT Pros & Developers. It's quick & easy.

radio button list question

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.