开发者

Using column two radio buttons in DataGrid

I created two template column in DataGrid.I assigned radio buttons to those columns.I created single selection by calling a javascript function for the first radio button. But,I cant't do single selection by calling a javascript function for the second radio button.Also,I can't run independently of each other.

      <asp:TemplateColumn HeaderText="">
     <ItemTemplate>
      <input type="radio" runat="server" id="rd1" onclick="SelectOne(this,'DataGrid')" VALUE="rd1"
       NAME="RadioGroup1" />
     </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="">

     <ItemTemplate>
      <input type="radio" runat="server" id="rd2" onclick="test(this,'DataGrid')" VALUE="rd2" 
      NAME="RadioGroup2" />      
     </ItemTemplate>
    </asp:TemplateColumn>

Javascript Code:

  <script  language="javascript">
  function Se开发者_如何学ClectOne(rd1,DataGrid)
  {
  all=document.getElementsByTagName("input");
  for(i=0;i<all.length;i++)
  {
  if(all.type=="radio")
   {
   var count=all.id.indexOf(DataGrid+'__ctl');
  if(count!=-1)
   {
    all.checked=false;
   }
   }
  }
   rd1.checked=true;
  }
  </script>


Is it necessary to run the radio buttons as server side controls? It may be easier to manage if you remove the runat=server and just emit a unique group name instead for each radio button that is part of the same group since that will prevent asp.net from changing the ID's. You can then check the selected values using Request["RadioGroupName"] instead of with the server control value property.

This will keep the groups working correctly, and it will make your javascript to select the radio buttons simpler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜