![](/img/trans.png)
[英]How I manage a “mode” using a class and radio buttons in Visual Studio?
[英]Visual Studio GridView in Web form: How to insert column with radio buttons
這是家庭作業,是給醫生評分的網站。 在我的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>
添加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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.