把断点设在这里,看有没有执行!
if(CB.Checked)
{
ID=newBook_DGrid.Items[i].Cells[1].Text;
oleDbDeleteCommand1.CommandText = "DELETE FROM NewBook where BookID ='"+ID+"'";
oleDbDeleteCommand1.ExecuteNonQuery();
}
if(CB.Checked)
{
ID=newBook_DGrid.Items[i].Cells[1].Text;
oleDbDeleteCommand1.CommandText = "DELETE FROM NewBook where BookID ='"+ID+"'";
oleDbDeleteCommand1.ExecuteNonQuery();
}
解决方案 »
- 一个解决方案里面两个网站,这两个网站必须都为应用程序,那么它们如何共享数据库?
- JS运行错误“缺少对象”
- .net做的登陆界面问题!!!
- 梅花雪中定义MzTreeView为何总是说未定义
- 问下各位前辈 -----
- 求助
- ASP.NET如何实现像QQ空间那样,当页面刷新时,不影响播放器的播放,播放器的音乐还是一直在播放?不会让音乐停止.小弟请教各位高手
- sql语句解释
- ASP.NET控制权限的问题`
- 用C#,如何将字符串"1,2,3,"转换成数组的型式呢
- 谁有asp.net与xml交互的例子给小的发一个!!![email protected] 高分求助!!!
- C#如何调用Web.Config,实现SqlServer连接的语句。
不知道是为什么应该出在CheckBox上吧。
???
CB=(CheckBox)(newBook_DGrid.Items[i].Cells[0].Controls[1]);试试CB=(CheckBox)(newBook_DGrid.Items[i].Cells[0].Controls[0]);
Controls[0]是个textbox因该是CB=(CheckBox)(e.Items[i].Cells[0].Controls[1]);
改成:CB=(CheckBox)(newBook_DGrid.Items[i].FindControl("CheckBox1"));
{
....
}
在for(int i=1; i<row; i++)上面设置断点,然后一步步调试。
<asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox Runat="server" ID="chk"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Project_ID" HeaderText="ProjectID"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
<br>
<asp:Button id="Button1" runat="server" Text="Delete"></asp:Button>下面是后台代码。
Page_Load函数:
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
SqlConnection conn = new SqlConnection("server=icyer;database=ChinaPackage;uid=sa;pwd=;");
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("SELECT Project_ID FROM tbProject ORDER BY Project_ID", conn);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();DataGrid1.DataSource = ds.Tables[0];
DataGrid1.DataBind();
}
}Button的Click事件函数:
private void Button1_Click(object sender, System.EventArgs e)
{
SqlConnection conn = new SqlConnection("server=icyer;database=ChinaPackage;uid=sa;pwd=;");
conn.Open();
SqlCommand cmd;
int i;
for (i = 0; i < DataGrid1.Items.Count; i++)
{
CheckBox chk = (CheckBox)DataGrid1.Items[i].FindControl("chk");
if (chk.Checked == true)
{
string strCommand = "DELETE FROM tbProject WHERE Project_ID='" + DataGrid1.Items[i].Cells[1].Text + "'";
cmd = new SqlCommand(strCommand, conn);
cmd.ExecuteNonQuery();
}
}SqlDataAdapter da = new SqlDataAdapter("SELECT Project_ID FROM tbProject ORDER BY Project_ID", conn);
DataSet ds = new DataSet();
da.Fill(ds);
DataGrid1.DataSource = ds.Tables[0];
DataGrid1.DataBind();
}