使嵌套的在GridView里的radiobutton实现单选(VS2005)
主要方法还是要结合脚本的。
在服务端给GridView添加如下方法:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
RadioButton rb = (RadioButton)e.Row.FindControl("RadioButton1");
rb.Attributes.Add("onclick", "judge(this)"); //给RadioButton添加onclick属性
}
}
在ASPX页面里添加下面的JS脚本
<script type="text/javascript">
var last = null;//最后访问的RadioButton的ID
function judge(obj)
{
if(last == null)
{
last = obj.id;
alert(last);
}
else
{
var lo = document.getElementById(last);
lo.checked = "";
//alert(last + " " + lo.checked);
last = obj.name;
}
obj.checked = "checked";
}
</script>
在服务端给GridView添加如下方法:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
RadioButton rb = (RadioButton)e.Row.FindControl("RadioButton1");
rb.Attributes.Add("onclick", "judge(this)"); //给RadioButton添加onclick属性
}
}
在ASPX页面里添加下面的JS脚本
<script type="text/javascript">
var last = null;//最后访问的RadioButton的ID
function judge(obj)
{
if(last == null)
{
last = obj.id;
alert(last);
}
else
{
var lo = document.getElementById(last);
lo.checked = "";
//alert(last + " " + lo.checked);
last = obj.name;
}
obj.checked = "checked";
}
</script>
posted on 2008-01-11 00:21 Above The Sky 阅读(174) 评论(0) 收藏 举报
浙公网安备 33010602011771号