在gridview中绑定单选按钮 [英] Binding Radio buttons in gridview

查看:76
本文介绍了在gridview中绑定单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家。



我在gridview中绑定单选按钮时遇到问题。我正在做一个项目在线测试。每个问题都有4/5单选按钮。在这里我写的示例代码



< asp:DataList ID =   dalsurvey runat =   server >  
< ItemTemplate>
< table>
< tr>
< td>
< span style = font-size:14px; font-weight:bold;<%#Eval( 答案% > < / span >
< / td >
< / tr >
< tr>
< td>
<输入名称= MyRadioButton class = radioButton type = radio id = ' <% #Eval(Description)%>' value = ' <%#Eval(Description)%>'<%#Convert.ToString(Eval( < span class =code-string> Description))!= hidden %> />
< asp:Label ID = Label2 runat = server Text = ' <%#Eval(说明)%>' > < / asp:标签 >
< / td >
< / tr >
< / 表格 >

< / ItemTemplate >
< / asp:DataList >





这里我应该只能选择一个。但我想在每个问题中选择一个单选按钮..我该怎么做...?

解决方案

在网格视图中添加Redio按钮你必须添加templatefield

如下:



 <   asp:GridView     ID  < span class =code-keyword> =  GridView1    runat   =  server >  
< >
< asp:BoundField DataF ield = PID HeaderText = PID ReadOnly = True SortExpression = ProductID / < span class =code-keyword>>
< asp:BoundField DataField = ProductName HeaderText = ProductName SortExpression = PName / >
< asp:BoundField DataField = 价格 HeaderText = 价格 SortExpression = 价格 / >
< < span class =code-leadattribute> asp:TemplateField HeaderText = 选择一个 >
< ItemTemplate >
< span class =code-keyword>< input name = RadioButton type = radio value =' <% #Eval( value%> ' / >
< / ItemTemplate >
< / asp:TemplateField >
< /列 >
< / asp:GridView >


hi experts.

i have a problem for binding radio buttons in gridview. i am doing a project online test. bing each question have 4/5 radio buttons. here i write the sample code

<asp:DataList ID="dalsurvey" runat="server">
                      <ItemTemplate>
                          <table>
                              <tr>
                                  <td>
                                      <span style="font-size:14px; font-weight:bold;"<%#Eval("Answers")%></span>
                                  </td>
                              </tr>
                              <tr>
                                  <td>
                                          <input name="MyRadioButton" class="radioButton" type="radio" id='<%# Eval("Description") %>' value='<%# Eval("Description") %>'  <%# Convert.ToString(Eval("Description")) != "" ? "" : "hidden"  %>  />
                                           <asp:Label ID="Label2" runat="server" Text='<%#Eval("Description") %>'></asp:Label>
                                  </td>
                              </tr>
                          </table>
                      
                           </ItemTemplate>
                  </asp:DataList>



here i should be able to select only one. but i want to select in each question one radio button.. how can i do this...?

解决方案

to add Redio button inside grid view you have to add templatefield
as given below :

<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:BoundField DataField="PID" HeaderText="PID" ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="PName" />
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
<asp:TemplateField HeaderText="Select One">
<ItemTemplate>
<input name="RadioButton" type="radio" value='<%# Eval("value") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</ asp:GridView >


这篇关于在gridview中绑定单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆