<asp:TemplateField ItemStyle-Width="40px" HeaderText="选择" ItemStyle-HorizontalAlign="Center">
  <ItemTemplate>
      <asp:CheckBox runat="server" ID="CheckBox1" />
  </ItemTemplate>
</asp:TemplateField>

 

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            CheckBox chk = (CheckBox)e.Row.FindControl("CheckBox1");
            e.Row.Attributes["onclick"] = chk.ClientID + ".checked=!" + chk.ClientID + ".checked;";
            //停止事件冒泡,防止选中状态混乱
            chk.Attributes["onclick"] = "window.event.cancelBubble = true;";
        }
    }

 

 

 

 

相关文章:

  • 2022-12-23
  • 2022-02-21
  • 2021-06-24
  • 2021-11-11
  • 2022-12-23
  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-12
  • 2022-12-23
  • 2021-06-16
  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
相关资源
相似解决方案