datalist多项删除
前台文件是:
<asp:datalist id= "Datalist1 " runat= "server ">
<HeaderTemplate>
<TABLE width= "100% " border= "0 " cellPadding= "1 " cellSpacing= "0 " bgcolor= "#6699FF ">
<TR>
<TD align= "center "> <strong> 标 题 </strong> </TD>
<TD width= "80 " align= "center "> <strong> 编辑 </strong> <input onclick= "checkalldelid(this.form) " type= "checkbox " value= "ON " name= "checkalldel ">
<script language= "javascript ">
<!--
function checkalldelid(form)
{
for (var i=0;i <form.delid.length;i++)
{
var e = form.delid[i];
if (e.name != 'chkall ')
e.checked = form.checkalldel.checked;
}
}
-->
</script>
</TD>
</TR>
</TABLE>
</HeaderTemplate>
<AlternatingItemStyle BackColor= "#E2E9FF "> </AlternatingItemStyle>
<ItemTemplate>
<TABLE style= "TABLE-LAYOUT: fixed; WORD-BREAK: break-all " height= "22 " cellSpacing= "0 " cellPadding= "0 "
width= "100% ">
<TR onmouseout= "this.style.backgroundColor="" " onmouseover= "this.style.backgroundColor="#dddddd" ">
<TD>
<asp:HyperLink id= "HyperLink1 " runat= "server " Target= "_blank " Text= ' <%# DataBinder.Eval(Container.DataItem, "RsjTitle ") %> ' NavigateUrl= ' ' ToolTip= ' <%# DataBinder.Eval(Container.DataItem, "RsjTitle ") %> '>
</asp:HyperLink>
</TD>
<TD width= "80 " align= "center ">
<asp:HyperLink id= "Hyperlink2 " runat= "server " Text= '修改 ' NavigateUrl= ' <%# DataBinder.Eval(Container.DataItem, "id ", "Admin_News_Edit.aspx?ID={0} ")%> ' ToolTip= '修改 '>
</asp:HyperLink>
<asp:CheckBox id= "CheckBox1 " runat= "server " value= ' <%# DataBinder.Eval(Container.DataItem, "ID ") %> '> </asp:CheckBox>
<asp:Label id= "Label1 " runat= "server "> <%# DataBinder.Eval(Container.DataItem, "id ") %> </asp:Label>
</TD>
</TR>
</TABLE>
</ItemTemplate>
</asp:datalist>
后台文件是:
/// <summary>
/// 执行Transact-SQL语句,对数据库记录做插入,修改,删除等操作
/// </summary>
/// <param name= "str_Sql "> Transact-SQL语句 </param>
public void ExeSql(string str_Sql)
{
Open();
myCommand = new SqlCommand(str_Sql,myConnection);
Response.Write(str_Sql);
Response.End();
myCommand.ExecuteNonQuery();
myCommand.Dispose();
}
/// <summary>
/// 在Repeater控件中删除数据库记录
/// </summary>
/// <param name= "id "> 数据库表关键字key字段名 </param>
/// <param name= "tablename "> 数据库表名 </param>
/// <param name= "cb_Id "> CheckBox控件id值 </param>
/// <param name= "lbl_Id "> Label控件id值 </param>
/// <param name= "myDataGrid "> DataGrid控件,即是数据绑定列表 </param>
public void ExeDel(string id,string tablename,string cb_Id,string lbl_Id,DataList myDataGrid)
{
for (int i=0;i <myDataGrid.Items.Count;i++)
{
CheckBox myCheckBox;
Label myLabel;
myCheckBox=(CheckBox)myDataGrid.Items[i].FindControl(cb_Id);
myLabel=(Label)myDataGrid.Items[i].FindControl(lbl_Id);
if(myCheckBox.Checked==true)
{
string strDelSql= "delete from "+tablename+ " where "+id+ "= "+myLabel.Text;
ExeSql(strDelSql);
}
}
}
private void Submit1_ServerClick(object sender, System.EventArgs e)
{
ExeDel( "id ", "RsjNews ", "CheckBox1 ", "Label1 ",Datalist1);
}
请问我前台和后台应该怎么修改才可以啊?
[解决办法]
Lz,好像这样写确实是不行的,我也碰到过这个问题,你这里改下就可以了:
<asp:Label id= "Label1 " runat= "server "> <%# DataBinder.Eval(Container.DataItem, "id ") %> </asp:Label>
--------------------------------
改成:
<asp:Label id= "Label1 " Text= ' <%# DataBinder.Eval(Container.DataItem, "id ") %> ' runat= "server "/>
现在就可以用Label1.Text属性