这是一个家庭作业,一个评价医生的网站。在我的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>
答案 0 :(得分:2)
添加asp:RadioButton而不是RadioButtonList。在每个RadioButton上指定GroupName,以便它们一起工作。像这样:
<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>