<!-- 在GridView里添加CheckBox选择控件 !--> <ItemTemplate> <asp:CheckBox ID="CheckBox" runat="server" /> </ItemTemplate>
//显示控件被选中的状态 for (int i = 0; i <= GridView1.Rows.Count - 1; i++) { CheckBox c = (CheckBox)GridView1.Rows[i].FindControl("CheckBox"); if (c != null) { if (c.Checked) { Response.Write("<script>alert('" + c.Checked.ToString() + "')</script>"); } } }
//注意!!!!!!!!!!! //一定要加这个IsPostBack,防止每次重新绑定 if (!IsPostBack) { Bind(); }