gridview中实现radiobutton的单选示例

c# 代码
复制代码 代码如下:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
RadioButton rb = (RadioButton)e.Row.FindControl("rbtSelect");
if (rb != null)
rb.Attributes.Add("onclick", "onClientClick('" + rb.ClientID + "','" + e.Row.RowIndex + "')"); //把选中行的RowIndex也传过去,提交后在服务器端取值时用
}
}

javascript代码
复制代码 代码如下:



hmtl代码:
复制代码 代码如下:

Width="648px" Font-Size="9pt" onrowcommand="GridView1_RowCommand"
DataKeyNames="id" onrowdatabound="GridView1_RowDataBound">









<%#Eval("AA") %>











你可能感兴趣的:(gridview中实现radiobutton的单选示例)