简体   繁体   English

Web窗体中的Visual Studio GridView:如何使用单选按钮插入列

[英]Visual Studio GridView in Web form: How to insert column with radio buttons

This is homework, a Web site to rate doctors. 这是家庭作业,是给医生评分的网站。 In my GridView, I want a column with rows of five radio buttons, so that each doctor can be rated. 在我的GridView中,我希望有一列包含五个单选按钮的行,以便可以对每个医生进行评分。 How do I get the radio buttons? 如何获得单选按钮? When I dragged a Radio Button List from the Toolbox, it didn't show up in Design mode. 当我从工具箱中拖动单选按钮列表时,它没有在设计模式下显示。

Here is my GridView: 这是我的GridView:

<asp:GridView ID="GridViewDoctor" runat="server" DataSourceID="ObjectDataSourceDoctor" DataKeyNames="DoctorPicture" AutoGenerateColumns="False" OnSelectedIndexChanged="GridViewDoctor_SelectedIndexChanged">
        <Columns>
            <asp:CommandField ShowSelectButton="True" />
            <asp:ImageField DataImageUrlField="DoctorPicture" HeaderText="DoctorPicture">
            </asp:ImageField>
            <asp:BoundField DataField="DoctorName" HeaderText="DoctorName" SortExpression="DoctorName" />
            <asp:BoundField DataField="DoctorSpecialty" HeaderText="DoctorSpecialty" SortExpression="DoctorSpecialty" />
            <asp:TemplateField HeaderText="Rate Now">
                <ItemTemplate>
                    <asp:RadioButtonList ID="RadioButtonList1" runat="server"></asp:RadioButtonList>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:CheckBoxField DataField="fave" HeaderText="fave" SortExpression="fave" />
        </Columns>
    </asp:GridView>

Add asp:RadioButton instead of RadioButtonList. 添加asp:RadioButton而不是RadioButtonList。 Specify GroupName on each RadioButton so they work together. 在每个RadioButton上指定GroupName,以便它们一起工作。 Something like this: 像这样:

<asp:GridView ID="GridViewDoctor" runat="server" DataSourceID="ObjectDataSourceDoctor" DataKeyNames="DoctorPicture" AutoGenerateColumns="False" OnSelectedIndexChanged="GridViewDoctor_SelectedIndexChanged">
    <Columns>
        <asp:CommandField ShowSelectButton="True" />
        <asp:ImageField DataImageUrlField="DoctorPicture" HeaderText="DoctorPicture"</asp:ImageField>
        <asp:BoundField DataField="DoctorName" HeaderText="DoctorName" SortExpression="DoctorName" />
        <asp:BoundField DataField="DoctorSpecialty" HeaderText="DoctorSpecialty" SortExpression="DoctorSpecialty" />
        <asp:TemplateField HeaderText="Rate Now">
            <ItemTemplate>
                <asp:RadioButton ID="RadioButton1" runat="server" GroupName="Group1"></asp:RadioButton>
                <asp:RadioButton ID="RadioButton2" runat="server" GroupName="Group1"></asp:RadioButton>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:CheckBoxField DataField="fave" HeaderText="fave" SortExpression="fave" />
    </Columns>
</asp:GridView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM