模板列选中几行删几行,在按钮的点击事件里怎么写?快速结帖
我这样写的不行
<asp:DataList id= "list1 " Runat= "server " Width= "100% ">
<ItemTemplate>
<tr>
<td width= "10% "> <asp:CheckBox ID= "chkSelect " runat= "server " /> </td>
</tr>
</ItemTemplate>
</asp:DataList>
<asp:ImageButton ID= "ImageButton1 " src= "images/shanchu.bmp " runat= "server " Style= "position: relative " OnClick= "ImageButton1_Click " />
cs:
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
int[] ID = new int[list1.Items.Count];
int i = 0;
foreach (DataListItem dl in list1.Items)
{
CheckBox chk = (CheckBox)dl.FindControl( "chkSelect ");
if (chk.Checked)
{
ID[i] = Convert.ToInt32(list1.DataKeys[dl.ItemIndex].ToString());
try
{
conn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings[ "ConnStr "]);
conn.Open();
cmd = new SqlCommand( "delete from zhanquxinxi where zh_id=ID[i] ", conn);
cmd.ExecuteNonQuery();
}
catch (Exception exp)
{
Response.Write(exp.Message);