2011-04-26 85 views
2

我想要一个单选按钮列的gridview以便 选择一行并执行一些任务。我添加了一个templatefield,但是当我运行该应用程序时,它让我选择所有行,但我想要的是 只选择一个。我怎样才能做到这一点?我的意思是,我希望单选按钮 作为一个组工作。在ASP.Net中选择一个单选按钮的gridview行

+0

所以,你问是只要一个行的单选按钮被选中禁用所有其他行? – diceler 2011-04-26 13:42:00

+0

将来,请使用有意义的标题。 “asp.net中的gridview”是一个非常宽泛的标题。 – DavRob60 2011-04-26 13:46:25

回答

0

您是否设置了“GroupName”属性?像这样的事情,例如:

<asp:GridView runat="server" ID="MyGridView"> 
    <Columns> 
     <asp:TemplateField HeaderText="Select"> 
      <ItemTemplate> 
       <asp:RadioButton runat="server" ID="myRB" GroupName="MyRadioButton" /> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Some Other Column"> 
      <ItemTemplate> 
       <%-- other stuff here --%> 
      </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 

你也可以用标准<Input>场更换<asp:RadioButton>,然后绑定Value=""属性,以独特的东西(如行ID,例如)。

0

尝试实例化模板中的单选按钮标记为文字,例如像这样:

internal class RadioButtonTemplate : ITemplate, INamingContainer 
     { 
      public void InstantiateIn(Control container) 
      { 
       Literal radButton = new Literal(); 
       radButton.ID = "RadioButtonMarkup"; 
       radButton.Text = "<input type='radio' name='myRadioButton' id='myRadioButton' value='<%# Eval(" + "CategoryID" + "%>'/>"; 
       container.Controls.Add(radButton); 
      } 
     } 
+0

这似乎是一个凌乱和详细的解决方案... – qJake 2011-04-26 13:49:43

+0

@SpikeX:相对于你的解决方案? – 2011-04-26 13:52:15

+0

我的解决方案更多的是一个建议或修复,假设他已经有了需要修复的代码。 – qJake 2011-04-26 13:53:52