是否可以以编程方式隐藏单选按钮列表的特定列表项?

问题描述 投票:10回答:5

我在aspx页面中使用了gridview。因为我有一个列表,其中单个单元格中的六个单选按钮水平对齐。

我需要隐藏第一个单选按钮。如何以编程方式实现这一目标?

<asp:GridView ID="CrowdRatingGrid" runat="server" AutoGenerateColumns="false" AllowPaging="true" PageSize="4" OnPageIndexChanging="CrowdRatingGrid_PageIndexChanging" ViewStateMode="Enabled">

<PagerSettings Mode="Numeric" PageButtonCount="4" />
<Columns>
<asp:TemplateField>
   <HeaderTemplate>
    Rating
    </HeaderTemplate>
    <ItemTemplate>
     <asp:RadioButtonList runat="server" ID="Rating" SelectedValue='<%# Bind("rating_id") %>'
                            RepeatDirection="Horizontal">
                            <asp:ListItem Value="0" />
                            <asp:ListItem Value="1" />
                            <asp:ListItem Value="2" />
                            <asp:ListItem Value="3" />
                            <asp:ListItem Value="4" />
                            <asp:ListItem Value="5" />
                        </asp:RadioButtonList>
                    </ItemTemplate>
                </asp:TemplateField>
         </Columns>
        </asp:GridView>

我需要隐藏值为0的列表项。我将如何实现?

c# asp.net gridview radiobuttonlist
5个回答
12
投票

是,您可以通过将其Enabled属性设置为Enabled来隐藏它:

false

根据OP的评论进行编辑。要完全摆脱它,您需要执行以下操作:

Rating.Items[0].Enabled = false;

然后,当您需要它时,您需要这样做:

Rating.Items.RemoveAt(0);

3
投票

编辑:好的,我对此进行了更深入的研究,看看当您将.NET设置为Horizo​​ntal时,.NET如何呈现RadioButtonList控件(它是一个表格,每个项目的Rating.Items.Insert(0, "0"); 都在其中)。

尝试一下:

<td>

1
投票
var bli = Rating.Items[ 0 ];
bli.Attributes.Add( "hidden", "hidden" );

它将100%起作用。


0
投票

工作正常。

radioListID.Items[index].Enabled = true/false;

Ex:

RadioButtonList.Items[index].Enable=True/False;

0
投票

旧线程,尽管可以做到这一点:

rdTypePackage.Items[1].Enabled = false;
© www.soinside.com 2019 - 2024. All rights reserved.