对asp.net不熟悉,刚开始使用!大家帮我看看,到底该怎么改才对?前台:用Gridview
*************************************************************
<asp:CheckBox ID="cbAll" runat="server" AutoPostBack="True" OnCheckedChanged="cbAll_CheckedChanged" /></td>
***********************************************************
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CC9966" BorderWidth="1px" CellPadding="4"
DataKeyNames="n_id" HorizontalAlign="Center"
Width="100%" BorderStyle="None" ShowHeader="False" AllowPaging="True" OnDataBound="GridView1_DataBound" > ***********************************************************<asp:TemplateField >
<ItemStyle HorizontalAlign="Center" Width="1%"/>
<ItemTemplate>
<asp:CheckBox ID="cb" runat="server" />
</ItemTemplate>
</asp:TemplateField>
***********************************************************
protected void Button2_Click(object sender, EventArgs e)
{
int Count_BoxCheckValue = this.GridView1.Rows.Count;
for (int rowindex = 0; rowindex < this.GridView1.Rows.Count; rowindex++)
{
if (((CheckBox)this.GridView1.Rows[rowindex].Cells[0].FindControl("cb")).Checked == true)
{
int n_id = Convert.ToInt32(this.GridView1.DataKeys[rowindex].Value);
if (!string.IsNullOrEmpty(n_id.ToString()))
{
AdoSql SqlDel = new AdoSql();
SqlDel.ExecuteSqlWrite("delete from tb_news where n_id=" + n_id);
this.DataBinds();
}
}
else
{
Count_BoxCheckValue--;
}
}
if (Count_BoxCheckValue <= 0)
{
Response.Write("<script language='javascript'>alert('没有选中需要处理的行记录!!')</script>");
}
DataBinds();
}
*************************************************************
<asp:CheckBox ID="cbAll" runat="server" AutoPostBack="True" OnCheckedChanged="cbAll_CheckedChanged" /></td>
***********************************************************
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CC9966" BorderWidth="1px" CellPadding="4"
DataKeyNames="n_id" HorizontalAlign="Center"
Width="100%" BorderStyle="None" ShowHeader="False" AllowPaging="True" OnDataBound="GridView1_DataBound" > ***********************************************************<asp:TemplateField >
<ItemStyle HorizontalAlign="Center" Width="1%"/>
<ItemTemplate>
<asp:CheckBox ID="cb" runat="server" />
</ItemTemplate>
</asp:TemplateField>
***********************************************************
protected void Button2_Click(object sender, EventArgs e)
{
int Count_BoxCheckValue = this.GridView1.Rows.Count;
for (int rowindex = 0; rowindex < this.GridView1.Rows.Count; rowindex++)
{
if (((CheckBox)this.GridView1.Rows[rowindex].Cells[0].FindControl("cb")).Checked == true)
{
int n_id = Convert.ToInt32(this.GridView1.DataKeys[rowindex].Value);
if (!string.IsNullOrEmpty(n_id.ToString()))
{
AdoSql SqlDel = new AdoSql();
SqlDel.ExecuteSqlWrite("delete from tb_news where n_id=" + n_id);
this.DataBinds();
}
}
else
{
Count_BoxCheckValue--;
}
}
if (Count_BoxCheckValue <= 0)
{
Response.Write("<script language='javascript'>alert('没有选中需要处理的行记录!!')</script>");
}
DataBinds();
}
解决方案 »
- debug自动生成文件夹
- 获取系统如cpu、内存、硬盘、网络等的实时情况
- VS 制作安装包是 出错!!!!各位大侠进来帮帮小弟呀,在线等待马上给分。
- textbox焦点丢失后,如何提交里面的数据
- 怎样引用另外一个页面
- C#中通过HttpWebRequest发送数据
- 关于word中取消选中问题,请大家帮忙!在线等
- 在.net2005中使用Remoting编程
- access数据库insert语句出现错误:"至少一个参数没有被指定值"
- 有人知道怎么删除VS.NET中的解决方案吗?就是在起始页上的。
- 为什么我从文本文件载入的汉字内容为乱字符呢?我已经用了GB2312了啊
- 谁有together for vs.net 2005的crack
foreach GridViewRow gr in GridView1.rows
if (((CheckBox)gr.Cells[0].FindControl("cb")).Checked == true)
…………
/// 执行SQL语句-写
/// </summary>
/// <param name="SqlString">SQL语句</param>
/// <returns></returns>
public Boolean ExecuteSqlWrite(string SqlString)
{
OleDbCommand SqlCmd = new OleDbCommand();
SqlCmd.Connection = new OleDbConnection(ConfigurationManager.AppSettings["ConnString1"] + System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["ConnString2"].Trim()));
SqlCmd.CommandText = SqlString;
SqlCmd.CommandType = CommandType.Text;
SqlCmd.Connection.Open();
SqlCmd.ExecuteNonQuery();
SqlCmd.Connection.Close();
return true; }
把这句注释掉,应该可以了
{
AdoSql SqlDel = new AdoSql();
SqlDel.ExecuteSqlWrite("delete from tb_news where n_id=" + n_id);
this.DataBinds();//楼主在这里对GridView重新绑定了吧?那么,更新了第一条记录后重新绑定,所有CheckBox也都恢复到未选中的状态了~ 这行代码应该去掉~
}