radio button list question

  • Thread starter Thread starter Yankee Imperialist Dog
  • Start date 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
 
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>
 
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?
 
Back
Top