aspx里的:
<asp:GridView ID="GridView1" runat="server" Width="100%" CellPadding="0" ForeColor="#333333"
AutoGenerateColumns="False" AllowPaging="true" PageSize="12" BorderColor="Silver"
BorderStyle="Solid" BorderWidth="1px" OnRowDataBound="GridView1_RowDataBound"
EmptyDataText="没有数据记录!!" DataKeyNames="id" AllowSorting="True">
<Columns>
<asp:TemplateField HeaderText="选择">
<HeaderTemplate>
<asp:CheckBox ID="chkAll" runat="server" ToolTip="全选" onclick="chkAll_Click(this)"
Text="分店名称" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkItem" runat="server" ToolTip="选择" Text='<%# Eval("d_name")%>' onclick="chkItem_Click(this)" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="状态" DataField="zt" />
<asp:BoundField HeaderText="单号" DataField="yewu_id" />
<asp:BoundField HeaderText="地址" DataField="addr" />
<asp:BoundField HeaderText="希望日期" DataField="xw_date" DataFormatString="{0:yyyy-MM-dd}" />
<asp:BoundField HeaderText="机型" DataField="ji_x" />
<asp:BoundField HeaderText="故障描述" DataField="g_z" />
</Columns>
<RowStyle BackColor="#F7F6F3" ForeColor="#284775" HorizontalAlign="Left" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="#A4D3EE" ForeColor="#333333" />
<PagerSettings Visible="False" />
<HeaderStyle Font-Bold="False" Font-Italic="False" Font-Size="12px" Height="25px"
BackColor="#8DB6CD" HorizontalAlign="Center" />
</asp:GridView>
CS里的
protected void Button2_Click(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
System.Web.UI.WebControls.CheckBox chk = (System.Web.UI.WebControls.CheckBox)GridView1.Rows[i].FindControl("chkItem");
if (chk.Checked == true)
{
int ddsID = Convert.ToInt32(GridView1.DataKeys[i].Value.ToString());
}
}
//Response.Redirect(url);