index.aspx部分代码
<asp:TemplateColumn>
<HeaderTemplate>
<input type="checkbox" id="CheckAll" onclick="return deselect(this.checked,this.id);" Runat="server" />
</HeaderTemplate>
<ItemTemplate>
<input type="checkbox" id="DeleteThis" onclick="return deselect(this.checked,this.id);"
Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>index.aspx.cs中代码 private void Button_del_Click(object sender, System.EventArgs e)
{
string chkids="";
bool chk_select=false;
foreach(DataGridItem i in DataGrid1.Items)
{
Boolean DelBox = ((CheckBox)i.FindControl("DeleteThis")).Checked; if(DelBox)
{
chk_select=true;
chkids=chkids+i.Cells[0].Text.ToString()+",";
}
} if(chk_select)
{
string dbpath=@"student.mdb";
string connStr="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source="+Server.MapPath(dbpath)+";";
OleDbConnection myconn=new OleDbConnection(connStr);
string sqlstr="delete * from info where id in (" + chkids.Substring (0, chkids.LastIndexOf (",")) + ")";
OleDbCommand mycommdel=new OleDbCommand(sqlstr,myconn);
myconn.Open();
mycommdel.ExecuteNonQuery();
myconn.Close();
bind();
}
---------------------------------------------------
指定的转换无效。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidCastException: 指定的转换无效。源错误:
行 138: foreach(DataGridItem i in DataGrid1.Items)
行 139: {
行 140: Boolean DelBox = ((CheckBox)i.FindControl("DeleteThis")).Checked;
行 141:
行 142: if(DelBox)
<asp:TemplateColumn>
<HeaderTemplate>
<input type="checkbox" id="CheckAll" onclick="return deselect(this.checked,this.id);" Runat="server" />
</HeaderTemplate>
<ItemTemplate>
<input type="checkbox" id="DeleteThis" onclick="return deselect(this.checked,this.id);"
Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>index.aspx.cs中代码 private void Button_del_Click(object sender, System.EventArgs e)
{
string chkids="";
bool chk_select=false;
foreach(DataGridItem i in DataGrid1.Items)
{
Boolean DelBox = ((CheckBox)i.FindControl("DeleteThis")).Checked; if(DelBox)
{
chk_select=true;
chkids=chkids+i.Cells[0].Text.ToString()+",";
}
} if(chk_select)
{
string dbpath=@"student.mdb";
string connStr="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source="+Server.MapPath(dbpath)+";";
OleDbConnection myconn=new OleDbConnection(connStr);
string sqlstr="delete * from info where id in (" + chkids.Substring (0, chkids.LastIndexOf (",")) + ")";
OleDbCommand mycommdel=new OleDbCommand(sqlstr,myconn);
myconn.Open();
mycommdel.ExecuteNonQuery();
myconn.Close();
bind();
}
---------------------------------------------------
指定的转换无效。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidCastException: 指定的转换无效。源错误:
行 138: foreach(DataGridItem i in DataGrid1.Items)
行 139: {
行 140: Boolean DelBox = ((CheckBox)i.FindControl("DeleteThis")).Checked;
行 141:
行 142: if(DelBox)
解决方案 »
- 可以让别人直接用迅雷下载你电脑上资料的软件!
- 在项目中有一个Web自定义控件,第二次打开设计页面是空白
- TextBox简单问题,求解
- 求一个ASP.NET显示隐藏页面的实例(像csdn那样的就行)
- 小弟马上要毕业了,想找个.net开发的工作,去深圳好,还是广州好?有什么要注意的么?
- 关于treeview的问题
- 高手请指导一下在SOSO地图处添加多个自定义标记--就70分了都给了--急急急!!!
- GridView中启用AutoGenerateDeleteButton后可否将“删除”置后?
- 关于正则表达式的问题!
- 拼接字符串错误
- 求救!
- 蛙蛙推荐:微软网络讲座系列教程视频下载(2004年1月到2005年4越)
for(int i=0;i<mycount;i++)
{
Boolean DelBox = ((CheckBox)this.DataGrid1.Items[i].FindControl("DeleteThis")).Checked;
if(DelBox == true)
{
chk_select=true;
chkids=chkids+i.Cells[0].Text.ToString()+",";
}
}
在删除按钮上加一个客户端事件,判断是否有复选框被选中,如果有则执行删除操作,如果没有则alert
或者在.cs中判断chkids是否为空
还是不行
能不能详细点,小弟惭愧。。
我用的htmlcontrol , CheckBox 是属于 WebCotrol 的,改成HtmlInputCheckBox就可以了。