<script type="text/javascript">
function setRadio(nowRadio)
{
var myForm,objRadio;
myForm=document.forms[0];
/**////alert(myForm);
for(var i=0;i<myForm.length;i++)
{
if(myForm.elements[i].type=="radio")
{
objRadio=myForm.elements[i];
/**////alert(objRadio.name);
if(objRadio!=nowRadio && objRadio.name.indexOf("GridView1")>-1 && objRadio.name.indexOf("RadioButton1")>-1)
{
alert(objRadio.name);
if(objRadio.checked)
{
objRadio.checked=false;
}
}
}
}
}
</script>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" ShowHeader="False" OnRowDataBound="GridView1_RowDataBound"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:RadioButton ID="RadioButton1" runat="server"/> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:Button ID="Button1" runat="server" Text="取选项" OnClick="Button1_Click"/> <asp:Label ID="Label1" runat="server"></asp:Label>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//给每个RadioButton1绑定setRadio事件
try
{
((RadioButton)e.Row.FindControl("RadioButton1")).Attributes.Add("onclick", "setRadio(this)");
}
catch (Exception)
{ }
}
protected void Button1_Click(object sender, EventArgs e)
{
//使用模版列里加RadioButton
Label1.Text = "";
foreach (GridViewRow gvr in GridView1.Rows)
{
try
{
if (((RadioButton)gvr.FindControl("RadioButton1")).Checked)
{
Label1.Text = "当前选中第" + Convert.ToString(gvr.RowIndex + 1) + "个";
break;
}
}
catch (Exception)
{ }
}
if (Label1.Text.Length == 0)
{
Label1.Text = "没有选中项";
}
}
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" ShowHeader="False"> <Columns> <asp:TemplateField> <ItemTemplate> <input type="radio" name="myRadio" value='<%# Container.DataItemIndex.ToString() %>'> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:Button ID="Button2" runat="server" Text="取选项" OnClick="Button2_Click" /> <asp:Label ID="Label2" runat="server"></asp:Label>
<script type="text/javascript">
function setNowRadio(v)
{
//alert(v);
var myForm,objRadio;
myForm=document.forms[0];
for(var i=0;i<myForm.length;i++)
{
if(myForm.elements[i].type=="radio")
{
objRadio=myForm.elements[i];
//alert(objRadio.name);
//alert(objRadio.value);
if(objRadio.value==v)
{
objRadio.checked=true;
}
}
}
}
<asp:Literal ID="jsLiteral" runat="server"></asp:Literal>
</script>
protected void Button2_Click(object sender, EventArgs e)
{
//使用模版列里加html控件Radio
if (Request.Form["myRadio"] == null)
{
Label2.Text = "没有选中项";
jsLiteral.Text = "";//*****
}
else
{
string value;
value = Request.Form["myRadio"].ToString();
Label2.Text = "当前选中第" + Convert.ToString(Convert.ToInt16(value) + 1) + "个";
jsLiteral.Text = "setNowRadio('" + value + "');";//*****
}
}
<asp:RadioButtonList ID="RadioButtonList1" runat="server"> </asp:RadioButtonList> <asp:Button ID="Button3" runat="server" Text="取选项" OnClick="Button3_Click" /> <asp:Label ID="Label3" runat="server"></asp:Label>
private void SetListItem(RadioButtonList rbt)
{
//给RadioButtonList加几个ListItem,用来测试数据
string item, space, info;
int per;
for (int i = 0; i < 3; i++)
{
per = 5;
item = "<div style='float:left; width:300px;'> 第 " + Convert.ToString(i + 1) + " 项</div>";
space = Convert.ToString(per * 3.50);
space = "<div style='float:left; background-color:MistyRose;border-color:Silver;border-width:1px;border-style:solid; width:" + space + "px;'></div>";
info = "<div style='float:left; width:70px;'> " + per.ToString() + "% 5票</div>";
info = item + space + info;
RadioButtonList1.Items.Add(new ListItem(info, ""));
}
}
<tr> <td> <input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="" /> <label for="RadioButtonList1_0"> <div style='float:left; width:300px;'> 第 1 项</div> <div style='float:left; background-color:MistyRose;border-color:Silver;border-width:1px;border-style:solid; width:17.5px;'></div> <div style='float:left; width:70px;'> 5% 5票</div> </label> </td> </tr>
protected void rbtnSel_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
((RadioButton)this.GridView1.Rows[i].FindControl("rbtnSel")).Checked = false;
}
((RadioButton)sender).Checked = true;//经典
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有