首先鄙视下dudu:不管你是什么文章,如果你加上一句:恳请dudu能够让我在首页挂一天,那么这文章就不会被dudu撤下来的,但是如果你没加,那不好意思,dudu的大刀就会向你举起!这是典型的顺风耳!

这段时间一直为网站的事醉心于代码,除了每天早晨给出交易信号外,基本上没有关注过行情了.但代码仅是我的爱好而已,操盘才是我的正业,趁现在心思还没有完全转到操盘上面来,把这个项目我整理的一些代码记下来,有点意义的就是如何给GridView加入单选按钮了.
在网上查阅了一些文章,无非就是:
1,放一个html单选控件:<input type="radio"...
2,放一个RadioButtonList;

这两种方法都有弊端;第一种如果我们要在后台取radiobutton的值就显得很麻烦,第二种会让我们不好布局,但是大家知道,如果仅仅是在GridView里面加入RadioButton,我们就实现不了单选,后面查阅了一老外的文章,找到了一种自认为比较好的方法,实现思路是:在后台给radiobutton加入个onclick属性,在前台当用户单击这个单选按钮的时候用js去遍历,取消其他单选的选择,下面是配合一个投票系统的代码,这个投票系统能够在后台自动生成是单选还是复选按钮,最后面的是一个实例.demo请见:http://www.yinuof.com/topiccontent.aspx?id=135&class=5
 1在GridView中加入单选按钮RadioButton<asp:Panel ID="literalVote" runat="server" Visible="false"> 
 2在GridView中加入单选按钮RadioButton                 <asp:GridView ID="gridVote" runat="server" AutoGenerateColumns="False" BackColor="#B6C9E7" CssClass="tableBack" CellPadding="3" CellSpacing="1" ShowHeader="False" Width="100%" DataKeyNames="this_id,vote_type,this_title" OnRowDataBound="gridVote_RowDataBound"> 
 3在GridView中加入单选按钮RadioButton                     <Columns> 
 4在GridView中加入单选按钮RadioButton                         <asp:TemplateField> 
 5在GridView中加入单选按钮RadioButton                            <ItemTemplate> 
 6在GridView中加入单选按钮RadioButton                               <asp:PlaceHolder ID="placeVote" runat="server" /> 
 7在GridView中加入单选按钮RadioButton                            </ItemTemplate> 
 8在GridView中加入单选按钮RadioButton                             <ItemStyle BackColor="White" /> 
 9在GridView中加入单选按钮RadioButton                         </asp:TemplateField> 
10在GridView中加入单选按钮RadioButton                         <asp:TemplateField> 
11在GridView中加入单选按钮RadioButton                            <ItemTemplate> 
12在GridView中加入单选按钮RadioButton                               <asp:Image ID="voteImage" Runat="server" Height="8px" Width='<%# FormatImage(Convert.ToInt32(Eval("vote_num").ToString())) %>' ImageUrl="img/bar2.gif"></asp:Image><%#Eval("vote_num"%> 
13在GridView中加入单选按钮RadioButton                            </ItemTemplate> 
14在GridView中加入单选按钮RadioButton                             <ItemStyle Width="50%" BackColor="White" /> 
15在GridView中加入单选按钮RadioButton                         </asp:TemplateField> 
16在GridView中加入单选按钮RadioButton                     </Columns> 
17在GridView中加入单选按钮RadioButton                 </asp:GridView> 
18在GridView中加入单选按钮RadioButton                 <div style="margin-top:5px;font-size:12px;color:#000000;"> 
19在GridView中加入单选按钮RadioButton                    <asp:Button UseSubmitBehavior="false" Text="我要投票" ID="buttonVote" runat="server" OnClick="buttonVote_Click" />&nbsp;【截至时间:<asp:Literal ID="literalTimeout" runat="server" />&nbsp;|&nbsp;<a href='voteuser.aspx?id=<%=Request.QueryString["id"] %>' class="aTitle" target="_blank">查看投票用户</a>】 
20在GridView中加入单选按钮RadioButton                 </div> 
21在GridView中加入单选按钮RadioButton             </asp:Panel>

js代码:
 1在GridView中加入单选按钮RadioButton<script language="javascript">            function SetUniqueRadioButton(nameregex, current) 
 2>

后台代码:
在GridView中加入单选按钮RadioButtonprotected void gridVote_RowDataBound(object sender, GridViewRowEventArgs e) 
    }

相关文章: