请教高手:ASP.NET--gridview中的radiobutton选择的问题

如题,<input id="rdoSelect" name="rdoSelect" type="radio" value="0")"/>
<input id="rdoSelect" name="rdoSelect" type="radio" value="1")"/>
<input id="rdoSelect" name="rdoSelect" type="radio" value="2")"/>
gridview里 有这样几个radio,请问怎样手动指定一列的radio选中? 用什么事件捕捉一列的checked发生变化?

第1个回答  2011-07-25
不知道是你没说明白还是我没看懂,你这三个radio是在同一列吗?
要选中同一个列的所有radio你可以给同一列的radio一个同样的name,然后用getElementByName获取所有相同name的radio然后遍历,一个一个改checked,要捕捉变化你可以给同一列的radio同一个onclick事件,在事件中处理。
gridview最后生成的还不就是一个table,你只要想像你是对一个table操作,就简单了。
第2个回答  2011-07-25
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
BackColor="#77A9CE" BorderColor="#6694B8" BorderStyle="None" BorderWidth="1px"
CellPadding="3" CellSpacing="1" GridLines="None" OnPageIndexChanging="GridView1_PageIndexChanging"
Style="font-size: 12px" Width="50%">
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<Columns>
<asp:TemplateField HeaderText="选择">
<ItemStyle HorizontalAlign="Center" Width="30px" Wrap="True" />
<HeaderStyle BackColor="#6694B8" ForeColor="WhiteSmoke" HorizontalAlign="Center"
Wrap="False" />
<ItemTemplate>
<input id="Radio1" name="Rad" type="radio" value='<%#DataBinder.Eval(Container.DataItem, "BelongCustomer")%>' />
</ItemTemplate>
<FooterStyle Wrap="True" />
</asp:TemplateField>
<asp:BoundField DataField="BelongCustomer" HeaderText="名称" SortExpression="cname">
<HeaderStyle BackColor="#6694B8" ForeColor="WhiteSmoke" Wrap="False" />
</asp:BoundField>
</Columns>
<RowStyle BackColor="#FBFCFE" ForeColor="Black" HorizontalAlign="Center" />
<EmptyDataTemplate>
<div align="center">
<font color="white">无相关数据!</font></div>
</EmptyDataTemplate>
<SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#6694B8" ForeColor="Transparent" HorizontalAlign="Right" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" Wrap="False" />
<AlternatingRowStyle BackColor="#E6EDF7" />
</asp:GridView>
<input id="Button1" onclick="return checkbutton();" type="button" value="确定" />
<input id="Button2" onclick="return closewin();" type="button" value="返回" />
</div>
</form>
</body>
</html>
<script language="javascript">
function checkbutton()
{
var a=0
for(var i=0;i<document.Form1.elements.length;i++)
{
if(document.Form1.elements[i].checked==true)
{
a=a+1;
}
}

if(a==1)
  {
sendFromChild();
}
else
{
alert('提交数据失败,未选中项!');
return false;
}

}/////

var getFromParent=window.dialogArguments;
function CheckSelect()
{
for(var i=0;i<window.document.Form1.elements.length;i++)
{
var e = Form1.elements[i];
if (e.checked)
{
return e.value;
}
}
var retrunstr="";
return retrunstr;
}

function sendFromChild()
{
window.returnValue=CheckSelect();

window.close();
}

window.onbeforeunload = function()
{
var n = window.event.screenX - window.screenLeft;
var b = n > document.documentElement.scrollWidth-20;
if(b && window.event.clientY < 0 || window.event.altKey)
{

}

}
//关闭
function closewin()
{
window.returnValue="";
window.close();
}
</script>本回答被提问者和网友采纳
相似回答