Friday, June 5, 2015

How to hide a particular list item of radiobuttonlist

My friend working in asp.net he has used gridview in aspx page. In this case he want to hide the particular radiobutton from the radiobuttonlist.

So I helped him to fix.

<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>


I found the solution to remove the RadioButton particular List from the RadioButtonList using the following the steps

Rating.Items[0].Enabled = false;


Editing based on comment by OP. To completely get rid of it you'll need to do this:

Rating.Items.RemoveAt(0);


and then when you want it back you'll need to do this:

Rating.Items.Insert(0, "0");

No comments:

Post a Comment