1. 获取GridView中CheckBox所选行的字段,即使是在绑定了数据源的时候,也可以获取选中的CheckedUnBindCheckBox对应的各个列的字段
使用时根据实际情况适当的修改即可。
string test = ""; for (int i = 0; i < GridView1.Rows.Count; i++) { if (((CheckBox)(GridView1.Rows[i].Cells[0].Controls[0])).Checked == true) { test += GridView1.Rows[i].Cells[1].Text.ToString() + ","; } } Response.Write("<script>alert('" + test + "')</script>"); return;
2. 附GridView的部分属性代码(自用)
<asp:GridView ID="GridView1" Width="100%" runat="server" AllowMultiColumnSorting="False" DataSourceID="ObjeDataSource1" CssClass="ContentPageDataGrid" EnableModelValidation="True" FocusColor="" IsSortAscending="False" MouseOverColor="" NeedRowMark="False" NeedUnBindCheckBoxColumn="True" UnBindCheckBoxColumnHeaderTextAlign="Left" UnBindCheckBoxColumnLocation="FirstColumn" UnBindCheckBoxHeaderText="" UnBindCheckBoxText="" AutoGenerateColumns="False" BorderWidth="1px" CanRowClick="False"> </asp:GridView>