string sql = "";
string docID = "";
bool b = false;
// 为什么的不到选中的checkbox???????????????????????
//循环检查GridView中被选中的checkbox
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
b = ((CheckBox)GridView1.Rows[i].FindControl("CheckBox1")).Checked;
// 如果CheckBox被选中则删除文档
if (b)
{
// 获取文档ID
docID = GridView1.Rows[i].Cells[0].Text.Trim(); sql = "DELETE FROM relationSystemDocument WHERE systemInfoID='"
+ txtSysID.Text.Trim() + "' AND systemEditionID='"
+ txtSysEditionID.Text.Trim() + "' AND documentID=" + Convert.ToDecimal(docID); WebFunction.ExecuteSql(sql); sql = "";
docID = "";
}
}
为什么明明已经选中的CheckBox,所得到的bool值都是false呢,同样的代码,在以前使用过,正常呀
模版列CheckBox的ID绝对没有错,是CheckBox1
string docID = "";
bool b = false;
// 为什么的不到选中的checkbox???????????????????????
//循环检查GridView中被选中的checkbox
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
b = ((CheckBox)GridView1.Rows[i].FindControl("CheckBox1")).Checked;
// 如果CheckBox被选中则删除文档
if (b)
{
// 获取文档ID
docID = GridView1.Rows[i].Cells[0].Text.Trim(); sql = "DELETE FROM relationSystemDocument WHERE systemInfoID='"
+ txtSysID.Text.Trim() + "' AND systemEditionID='"
+ txtSysEditionID.Text.Trim() + "' AND documentID=" + Convert.ToDecimal(docID); WebFunction.ExecuteSql(sql); sql = "";
docID = "";
}
}
为什么明明已经选中的CheckBox,所得到的bool值都是false呢,同样的代码,在以前使用过,正常呀
模版列CheckBox的ID绝对没有错,是CheckBox1
解决方案 »
- sql数据库多条件查询问题?
- Nhibernate返回指定列问题
- asp.net页面中iframe标签变成<ad- me><AD- AME>了
- 在DATAGRID中使用自定义控件的翻页问题.
- 一个简单问题~~
- 新手求教!有关webservice
- DataGrid左边的空白能标上序列吗?DataGrid的表头能象Excel的表头吗(即A,B....AB,AC等等)?
- 要做一个类似于<select></select>得控件,各位大虾青帮忙,急急急!
- web打印的时候在代码里面去掉页眉页脚?
- 怎样改变上传的图片的大小?
- 超时时间已到。在操作完成之前超时时间已过或服务器未反应
- ASP.NET和Dreamweaver 配合用,APS编完页面Dreamweaver 可以在上边修改么,能识别么
{
CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox");
if (ch.Checked)
{
/////
}
}
{
CheckBox cbAll = (CheckBox)sender;
if(cbAll.Text=="全选")
{
foreach(DataGridItem dgi in dgShow.Items)
{
CheckBox cb = (CheckBox)dgi.FindControl("cbSelect");
cb.Checked = cbAll.Checked;
}
}
}
private void btnDelete_Click(object sender, System.EventArgs e)
{
foreach(DataGridItem dgi in dgShow.Items)
{
CheckBox cb = (CheckBox)dgi.FindControl("cbSelect");
if(cb.Checked)
{
//以下执行删除操作
int nID = int.Parse(dgi.Cells[0].Text);
string strSql = "delete from tbStudentinfo where studentid="+nID;
ExecuteSql(strSql);
}
}
dgShow.CurrentPageIndex = 0;
BindData();
}
因为没有提交
============================================================================
不明白……
因为你在Page_Load时候重新绑定了GridView导致所有CheckBox重置了。你检查一下应该是我说的问题。
===============================================================================
正解,因为该页面有一个弹出窗口,向数据库添加与文档的关联,返回的时候自然要在Page.IsPostBack属性中重新绑定以下数据。有什么解决方法么?
as following:if(!IsPostBack) {
GridView1.DataSource = GetMyDataSOurce();
GridView1.DataBind();
}Good Luck!
重新绑定后,控件状态就变了,你要在重新绑定前判断.
============================================
会尝试你的方法的
CheckBox chkEport = null;
String sExam_Code = "";
foreach (GridViewRow gridviewrow in gv.Rows)
{
chkEport = (CheckBox)gridviewrow.FindControl("chkEport");
if (chkEport.Checked)
{
sExam_Code = gridviewrow.Cells[1].Text.Trim();
ick_count = ick_count + 1;
}
}
Do you rebind the GridView at the PostBack phase(when u fire the delete event)?
as following:if(!IsPostBack) {
GridView1.DataSource = GetMyDataSOurce();
GridView1.DataBind();
}Good Luck!
==============================================================
这样页面IsPostBack的时候,就不绑定数据了?那怎么及时反映GridView中的变化呀。
应该是((CheckBox)GridView1.Rows[i].FindControl("CheckBox1")).State吧!好像是State判断是否选中,查msdn吧,肯定不是....Checked
((CheckBox)GridView1.Rows[i].FindControl("CheckBox1")).Checked=true//才是设置属性
应该是((CheckBox)GridView1.Rows[i].FindControl("CheckBox1")).State吧!好像是State判断是否选中,查msdn吧,肯定不是....Checked
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
哪有State属性……
if (!this.IsPostBack)//确保可以正确获得CHECKBOX的状态
{
this.gv_UserList.DataBind();
} protected void Lbtn_UserDetai_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in this.gv_UserList.Rows)
{
//Control ctrl = row.FindControl("cbSel");
CheckBox ctrl = (CheckBox)row.FindControl("cbSel"); if ((ctrl).Checked)
{
TableCellCollection cell = row.Cells;
string studentCode = cell[1].Text;
}
} }
这样可以解决
if (!this.IsPostBack)//确保可以正确获得CHECKBOX的状态
{
this.gv_UserList.DataBind();
} protected void Lbtn_UserDetai_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in this.gv_UserList.Rows)
{
//Control ctrl = row.FindControl("cbSel");
CheckBox ctrl = (CheckBox)row.FindControl("cbSel"); if ((ctrl).Checked)
{
TableCellCollection cell = row.Cells;
string studentCode = cell[1].Text;
}
} }
这样可以解决
if (!this.IsPostBack)//确保可以正确获得CHECKBOX的状态
{
this.gv_UserList.DataBind();
} protected void Lbtn_UserDetai_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in this.gv_UserList.Rows)
{
//Control ctrl = row.FindControl("cbSel");
CheckBox ctrl = (CheckBox)row.FindControl("cbSel"); if ((ctrl).Checked)
{
TableCellCollection cell = row.Cells;
string studentCode = cell[1].Text;
}
} }
这样可以解决