关于控制datagrid里checkBox的状态问题.
有两列.一列是checkbox模板列.一列是 "名字 "的超连接列.点击名字列后会弹出一个新窗口.现在想实现,在点击名字列的同时,能把对应这行的checkBox也变成选重状态.请问怎么实现呀!感谢.
<asp:TemplateColumn>
<HeaderStyle Width= "8px "> </HeaderStyle>
<ItemStyle VerticalAlign= "Top "> </ItemStyle>
<ItemTemplate>
<asp:CheckBox id= "chkSelect " runat= "server "> </asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:HyperLinkColumn DataTextField= "cName " HeaderText= "姓名 " Target= "_blank " DataNavigateUrlField= "iHumanID "
DataNavigateUrlFormatString= "../../Resume.aspx?humanID={0} ">
<HeaderStyle HorizontalAlign= "Center "> </HeaderStyle>
<ItemStyle HorizontalAlign= "Center "> </ItemStyle>
</asp:HyperLinkColumn>
------解决方案-------------------- private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
CheckBox cbx =e.Item.FindControl( "chkSelect ") as CheckBox;
if(cbx!=null)
{
string chkID =cbx.ClientID;
((System.Web.UI.WebControls.HyperLink) e.Item.Cells[1].Controls[0]).Attributes.Add( "onclick ", "document.getElementById( ' "+chkID+ " ').checked=true ");
}
}
改成这样吧