This is actually a known issue that radio buttons in the ItemTemplate are not mutually exclusive: BUG: Radio Buttons Are Not Mutually Exclusive When Used in a Repeater Server Control http://support.microsoft.com/?scid=kb;en-us;Q316495 We can workaround this by using either client side script or handling the CheckedChanged event on the server side. Here is the way to handle the CheckedChanged event. Please note that this method requires more postback than client side script does: 1. We can use a Datagrid's to display the rows as Lewis suggested. 2. Create a ItemTemplate column and add a RadioButton to the column. Bind the RadioButton appropriately. 3. Open the ASPX view of the page, add "OnCheckedChanged" attribute to the <asp:RadioButton> element, and make it point to a public handler method defined in the code behind file. Here is a code snippet for example: In ASPX file ========== <asp:TemplateColumn HeaderText="RadioCol"> <ItemTemplate> <asp:RadioButton id="RadioButton4" AutoPostBack="True" OnCheckedChanged="RadioButton4_CheckedChanged" runat="server" GroupName="DtFrom"></asp:RadioButton> </ItemTemplate> </asp:TemplateColumn> In the code behind file =================== public void RadioButton4_CheckedChanged(object sender, System.EventArgs e) { RadioButton rb=(RadioButton)sender; Response.Write(rb.ClientID.ToString()); //This line is just for test purpose. for (int i =0 ; i <DataGrid1.Items.Count; i++) { ((RadioButton)DataGrid1.Items[i].Controls[0].Controls[1]).Checked= false; } // check the selected radio button rb.Checked= true; } To get the selected RadioButton when you submit the page, I think you can try the FindCotrol method. You could also handle the submit button's server-side click event and iterate the rows of the table to find out the selected radio button.
单选的可以参考
<asp:TemplateColumn HeaderText="序号">
<ItemTemplate>
<INPUT id=radio onclick=fun_option(this) type=radio value='<%# DataBinder.Eval(Container.DataItem,"UserID") %>' name=radio> </ItemTemplate> </asp:TemplateColumn>
你是在什么时候打开新页面呢?
如果超连接打开,参考如下
<asp:TemplateColumn HeaderText="省市">
<ItemTemplate>
<a href='form1.aspx?id=<%# DataBinder.Eval(Container.DataItem,"UserID") %>&name=<%# DataBinder.Eval(Container.DataItem,"UserName") %>' target="_blank">
<%# DataBinder.Eval(Container.DataItem,"UserName") %>
</a>
ItemTemplate>
</asp:TemplateColumn>参考
http://singlepine.cnblogs.com/articles/266538.html
例如:<INPUT id=radio onclick=fun_option(this) type=radio value='<%# DataBinder.Eval(Container.DataItem,"UserID") %>' name=radio> 我要把选中的userID号取出来放在一个变量中,然后调用存储过程删除这条以userID为主码的记录,怎么取出来呢?
我已经照着做了,但ms删不掉。datagrid里显示的数据是调用一个存储过程,而这个存储过程调用了一个视图,并且把主码的列名重新命名了,删除的语句则是直接作用于基本表。这些与不能删除有关系吗?
就是这样
http://support.microsoft.com/?scid=kb;en-us;Q316495 We can workaround this by using either client side script or handling the CheckedChanged event on the server side. Here is the way to handle the CheckedChanged event. Please note that this method requires more postback than client side script does: 1. We can use a Datagrid's to display the rows as Lewis suggested.
2. Create a ItemTemplate column and add a RadioButton to the column. Bind the RadioButton appropriately.
3. Open the ASPX view of the page, add "OnCheckedChanged" attribute to the <asp:RadioButton> element, and make it point to a public handler method defined in the code behind file. Here is a code snippet for example:
In ASPX file
==========
<asp:TemplateColumn HeaderText="RadioCol">
<ItemTemplate>
<asp:RadioButton id="RadioButton4" AutoPostBack="True"
OnCheckedChanged="RadioButton4_CheckedChanged" runat="server"
GroupName="DtFrom"></asp:RadioButton>
</ItemTemplate>
</asp:TemplateColumn> In the code behind file
===================
public void RadioButton4_CheckedChanged(object sender, System.EventArgs e)
{
RadioButton rb=(RadioButton)sender;
Response.Write(rb.ClientID.ToString()); //This line is just for test purpose.
for (int i =0 ; i <DataGrid1.Items.Count; i++)
{
((RadioButton)DataGrid1.Items[i].Controls[0].Controls[1]).Checked= false;
}
// check the selected radio button
rb.Checked= true;
} To get the selected RadioButton when you submit the page, I think you can try the FindCotrol method. You could also handle the submit button's server-side click event and iterate the rows of the table to find out the selected radio button.