知识点 - DataGrid中Radio实现单选
前台DataGrid代码:
<asp:datagrid id="dgRadioButton" runat="server" DataKeyField="Id" AutoGenerateColumns="False" AllowPaging="True" >
<Columns>
<asp:TemplateColumn HeaderText="选择">
<ItemTemplate>
<input type=radio name="select" id="rbtnSelected" value='<%# DataBinder.Eval(Container.DataItem,"绑定值")%>'>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="绑定值" HeaderText="列标题"></asp:BoundColumn>
</Columns>
</asp:datagrid>
<Columns>
<asp:TemplateColumn HeaderText="选择">
<ItemTemplate>
<input type=radio name="select" id="rbtnSelected" value='<%# DataBinder.Eval(Container.DataItem,"绑定值")%>'>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="绑定值" HeaderText="列标题"></asp:BoundColumn>
</Columns>
</asp:datagrid>
CS代码实现(当点击提交按钮时,选定行被提交到另一页面)
private void btnSubmit_Click(object sender, System.EventArgs e)
{
string strSelectRow = "";
for(int i=0;i<this.dgRadioButton.Items.Count;i++)
{
strSelectRow = Page.Request.Form.Get("select");
}
if(strSelectRow != "")
{
Response.Redirect("链接地址?参数=" + strSelectRow);
}
else
{
this.popupMessage("请选择");
return;
}
}
{
string strSelectRow = "";
for(int i=0;i<this.dgRadioButton.Items.Count;i++)
{
strSelectRow = Page.Request.Form.Get("select");
}
if(strSelectRow != "")
{
Response.Redirect("链接地址?参数=" + strSelectRow);
}
else
{
this.popupMessage("请选择");
return;
}
}