多选删除的问题
aspx文件<asp:DataGrid ID="IpGrid" runat="server" OnItemDataBound="IpGrid_ItemDataBound" Width="98%" AutoGenerateColumns="false">
<Columns>
<asp:BoundColumn DataField="id" HeaderText="ID" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="80"></asp:BoundColumn>
<asp:BoundColumn DataField="IP" HeaderText="IP" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="200"></asp:BoundColumn>
<asp:BoundColumn DataField="i_datetime" DataFormatString="{0:yyyy-MM-dd}" HeaderText="日期" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="90"></asp:BoundColumn>
<asp:TemplateColumn ItemStyle-HorizontalAlign="Center" ItemStyle-Width="20">
<HeaderTemplate>
<input onclick="checkFormAll(this.checked)" type="checkbox" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="IpChk" runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
C#文件
protected void DeleteBtn_Click(object sender, EventArgs e)
{
string id = null;
foreach (DataGridItem item in IpGrid.Items)
{
CheckBox Chk = (CheckBox)item.FindControl("IpChk");
if (Chk.Checked)
{
id += "," + IpGrid.DataKeys[item.ItemIndex];
}
}
if (id != null)
{
DataBase.ExecuteSql= "delete from nk_ip where id = (" + id.TrimStart(',') + ")");
}
}为什么ID取不出值呀,兄弟们给分析一下呀,在线等,谢谢
--------------------编程问答-------------------- 可能是没找到控件吧?还有可能是绑定DataGrid的事件没有写在IspostBack里面导致回发的时候将CheckBox清空了。
补充:.NET技术 , ASP.NET