假设CheckBox在第0列:
chk = (CheckBox)oDataGridItem.Cells[0].FindControl("chk");
chk = (CheckBox)oDataGridItem.Cells[0].FindControl("chk");
解决方案 »
- 在数据集xsd中的tableadpter中添加查询,需要where后面直接跟参数,该怎么做呢
- ASP.NET在那运行?
- ASP.NET 下用OracleDataAccess.dll文件,出现 innerEXCEPTION是怎么回事?
- Rss新闻采集?
- 如何实现打印指定定数据的打印
- DropDownList控件的一个小问题?
- 各位实现图片新闻...给一点思路..
- 如何在Javascript中控制服务器控件的隐藏和显示?
- 找大侠提供个金融行业外汇免费的api接口
- 如此问题,真是令人费解----各位兄弟,请进来看一下
- 紧急求助?cookies不能及时更新?
- 请教如何更新.net2005的服务器上的单个网页?
#region 删除
protected void lbDel_Click(object sender, EventArgs e)
{
for (int i = 0; i < gvArticleList.Rows.Count; i++)
{
CheckBox cbSel = (CheckBox)gvArticleList.Rows[i].FindControl("cbTitle");
if (cbSel.Checked)
{
string strId = gvArticleList.DataKeys[i].Value.ToString().Trim();//删除数据
...
}
#endregion
{
KindsInfoDB kindsinfo=new KindsInfoDB();
//CheckBox chk;
for (int i = 0; i < myDataGrid.Items.Count; i++)
{
CheckBox chk = (CheckBox)myDataGrid.Items[i].FindControl("chk");
if (chk.Checked)
{
try
{
kindsinfo.updateindetailkinds(API.getInt32(catalogueList.SelectedValue),API.getInt32(kindsList.SelectedValue));
}
catch(Exception ex)
{
string sRawURL = Request.RawUrl; if(sRawURL.IndexOf("?") > -1)
{
sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
}
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + Server.UrlEncode(ex.Message.Replace("\n"," ")));
}
}
Response.Write("<script>alert(\"归类完毕!\");</script>"); }
}
不能实现,dataGri控件还是会遍历所有行,然后更新了
你现在是在datagrid上查找
{
KindsInfoDB kindsinfo=new KindsInfoDB();
CheckBox chk;
int nID=0;
foreach(DataGridItem oDataGridItem in myDataGrid.Items)
{
nID = (int)myDataGrid.DataKeys[oDataGridItem.ItemIndex];//-----提示错误处
chk= (CheckBox)oDataGridItem.FindControl("chk");
if(chk.Checked)
{
kindsinfo.updateindetailkinds(nID,API.getInt32(catalogueList.SelectedValue),API.getInt32(kindsList.SelectedValue)); ...................
修改后存在错误:索引超出范围。必须为非负值并小于集合大小。参数名: index
高手门帮忙看看
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (cbox.Checked == true)
{
nID=(int)GridView1.Rows[i].Cells[1].Text.ToString();
.........//操作
}
}
试一下
private void Button2_Click(object sender, System.EventArgs e)
{
foreach (DataGridItem dgi in DataGrid1.Items )
{
CheckBox cb2 = (CheckBox)dgi.FindControl("CheckBox3");
if (cb2.Checked)
{
int nID = int.Parse(dgi.Cells[1].Text);
string strSql = "update tbStudentinfo set checked='"+1+"' where studentid="+nID;
ExecuteSql (strSql);
}
else
{
int nID = int.Parse(dgi.Cells[1].Text);
string strSql = "update tbStudentinfo set checked='"+0+"' where studentid="+nID;
ExecuteSql (strSql);
}
}
string strCon = System.Configuration.ConfigurationSettings.AppSettings["DSN"];
SqlConnection con = new SqlConnection(strCon);
SqlDataAdapter da = new SqlDataAdapter("Select * from tbStudentinfo where checked='" +1+"'",strCon);
DataSet ds = new DataSet();
da.Fill(ds,"studentinfo");
dgShow.DataSource = ds.Tables["studentinfo"].DefaultView;
dgShow.DataBind();
}
楼住能不能把当checkbox被选中后,
如何获取key和对应的数据库操作也帖出来看看
for (int i = 0; i < myDataGrid.Items.Count; i++)
{
CheckBox chk = (CheckBox)myDataGrid.Items[i].FindControl("chk");
if (chk.Checked)
{
Label lbl = (Label)myDataGrid.Items[i].Cells[1].FindControl("label10");//最重要的一行,label10取要修改数据库中行的id
string nID= lbl.Text;
try
{
kindsinfo.updateindetailkinds(nID,API.getInt32(catalogueList.SelectedValue),API.getInt32(kindsList.SelectedValue));
........