radio button list question

  • Thread starter Yankee Imperialist Dog
  • Start date
Y

Yankee Imperialist Dog

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
 
K

Ken Cox [MVP]

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<string> GetDataCollection()
{
List<string> sites = 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>
 
Y

Yankee Imperialist Dog

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top