I have used gridview in my aspx page.. In that I have a list with six radio buttons in a single cell aligned horizontally.
I need the 1st radio button to be hidden. How to achieve that programmatically?
<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 need the List Item with value=0 to be hidden. How would I achieve this?
Yes, you can hide one by setting its Enabled
property to false
:
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");