Search code examples
c#asp.netgridviewradiobuttonlist

Hide text of radiobuttonlist inside gridview


Here’s a radiobuttonlist in a template field of gridview (using sqldatasource):

           </asp:TemplateField>
                <asp:TemplateField HeaderText="  -- 1 -- 2 -- 3 -- 4 -- 5 --  " HeaderStyle-Width="200px"  ItemStyle-HorizontalAlign="Center" >     
                    <ItemTemplate>
                <asp:RadioButtonList AutoPostBack="True" ID="rblRating" runat="server"  
                SelectedIndex='<%# Convert.ToInt32(DataBinder.Eval(Container.DataItem , "Rating"))%>'
                OnSelectedIndexChanged="rblRating_SelectedIndexChanged" 
                RepeatDirection="Horizontal">
                    <asp:ListItem Value="0"></asp:ListItem>
                    <asp:ListItem Value="1"></asp:ListItem>
                    <asp:ListItem Value="2"></asp:ListItem>
                    <asp:ListItem Value="3"></asp:ListItem>
                    <asp:ListItem Value="4"></asp:ListItem>
                    <asp:ListItem Value="5"></asp:ListItem>                        
                </asp:RadioButtonList>
              <%--<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Select a Rating" ControlToValidate="rblRating"></asp:RequiredFieldValidator>--%>
            </ItemTemplate>
            <FooterTemplate>
            <div class="divright"><asp:Label ID="lblSum" runat="server" Text="Sum ratings: " Font-Size="Small" ForeColor="#3399FF"></asp:Label></div> 
            <div class="divleft2"><asp:Label ID="lblAverage" runat="server" Width="50px" Font-Bold="True"></asp:Label></div>
              </FooterTemplate>

<HeaderStyle Width="150px"></HeaderStyle>

<ItemStyle HorizontalAlign="Center"></ItemStyle>
        </asp:TemplateField>

The Text values of each radiobuttonlist item have “1”, “2”, “3” etc beside them and I want them to be blank since I am designating the rating/number (1 through 5) in the header. I’ve left out Text in aspx, and set Text to blank in the radiobuttonlist ListItem Collection editor properties but the Values are still showing up. How to hide?


Solution

  • Simply specify the Text property and leave them empty.

    <asp:ListItem Value="0" Text=""></asp:ListItem>
    <asp:ListItem Value="1" Text=""></asp:ListItem>
    <asp:ListItem Value="2" Text=""></asp:ListItem>
    <asp:ListItem Value="3" Text=""></asp:ListItem>
    <asp:ListItem Value="4" Text=""></asp:ListItem>
    <asp:ListItem Value="5" Text=""></asp:ListItem>