单选按钮列表-禁用列表项 [英] Radiobuttonlist - disabling a list item

查看:90
本文介绍了单选按钮列表-禁用列表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从表生成的列表中禁用2个单选按钮.关于此的文章很多,但是如果列表来自表,则几乎没有解决这个问题的文章. RadioButtonlist是从包含作业单位或团队的SQL表中生成的.我想从列表中禁用其中两个团队(市场营销和SRT).作业单元表由其他应用程序使用,因此从表中删除2个作业单元将影响其他应用程序.我可以在SelectMethod中做到这一点,但这也是共享的.

如何从此生成的列表中禁用两个团队?

这是我的代码:

.ASPX

I am trying to disable 2 radiobuttons from a list that is generated from a table. There are a lot of articles on this but few if any address the issue when the list comes from a table. The RadioButtonlist is generated from an SQL table that contains Job Units or Teams. I want to disable two of the Teams (Marketing and SRT) from the list. The Job Units table is used by other applications so removing the 2 Job Units from the table would affect the other applications. I could do it in the SelectMethod but that is also shared.

How can I disable the two Teams from this generated list?

Here is my code:

.ASPX

<asp:Label ID="Label1" runat="server" Text="Team:" ></asp:Label>             
        <asp:RadioButtonList ID="rblTeam" runat="server" AutoPostBack="True" DataSourceID="odsTeam" 

             Font-Size="X-Small" RepeatDirection="Horizontal"  BorderStyle="Outset"  RepeatColumns="6"  

            DataValueField="JobUnitID" DataTextField = "JobUnitAbbreviation" OnLoad="Page_Load" >
        </asp:RadioButtonList>
        
        <!-- data source for the team drop down list -->
        <asp:ObjectDataSource ID="odsTeam" runat="server" 

            SelectMethod="GetCSOJobUnits" TypeName="SupportBAL.SupportBAL">
        </asp:ObjectDataSource><br />





protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Page.SetFocus(txtCaseNumber);
            rblTeam.SelectedIndex = 0;
            int TodaysDay2 = DateTime.Today.Day;
            int TodaysMonth2 = DateTime.Today.Month;
            int TodaysYear2 = DateTime.Today.Year;
            txtLogDate.Text = TodaysMonth2 + "/" + TodaysDay2 + "/" + TodaysYear2;
        }
    }



如果我是在.ASPX代码中创建列表,则没问题.由于该列表正在生成,因此我陷入了困境.



If I was creating the list in the .ASPX code, no problem. Since the list is being generated, I am stuck.

Any help and advise will be much appreciated.

推荐答案

1)禁用项目:

在列表中为您的项目搜索(可以通过文本或按值进行搜索)并将其禁用:

1) Disabling items:

Serach for your item in the list (you can do it or by text or by value) and disable it:

ListItem srtItem = rblTeam.Items.FindByValue("SRT");

if (srtItem != null)
   srtItem.Enabled = false;



该代码应该有效.

2)重写一些代码:

这个:



This code should work.

2) Rewriting some code:

This:

int TodaysDay2 = DateTime.Today.Day;
int TodaysMonth2 = DateTime.Today.Month;
int TodaysYear2 = DateTime.Today.Year;
txtLogDate.Text = TodaysMonth2 + "/" + TodaysDay2 + "/" + TodaysYear2;



可以很容易地写成(如果您想避免当前的文化):



can easily be written as (if you are trying to avoid a current culture):

txtLogDate.Text = DateTime.Now.ToString("MM\\/dd\\/yyyy");



此处更多信息:
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx [ ^ ]
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx [ ^ ]


干杯



More information here:
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^]
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^]


Cheers


这篇关于单选按钮列表-禁用列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆