if(((CheckBox)DataGrid1.Items[i].FindControl("GroupId")).Checked==true)
解决方案 »
- .net中如何动态实现TextBox按钮
- DropDownList 对应链接地址问题---高手看过来
- system.invalidoperationexception异常问题
- 很菜的问题啊,求大家帮个帮!急!
- 请XDJM们给我篇文章翻译翻译吧---关于新闻发布系统on asp.net的英文文档,谢谢
- asp.net视频上传进度条问题
- 关于局部样式变换打印的问题,200分给你来拿
- cookie的使用问题
- asp.net 播放语音
- 新手问一个非常easy的问题(我写的asp.net代码页面怎样嵌入在另一个html的表格中呢?
- 在webform中,放好了控件,但是运行时各个控件的位置都乱了!
- 安装了Oracle客户端,为什么连不通Oracle呢
我是这样遍历的,你参考一下
/// <summary>
/// 求合计
/// </summary>
/// <param name="myDG">当前操作的DG</param>
/// <param name="FristCell">求和的第一个值端</param>
/// <param name="SecondCell">求和的第一个值端</param>
/// <param name="mytablename">表的名称</param>
void myTotalPrice(DataGrid myDG,int FristCell,int SecondCell,string mytablename,string myTotalField)
{
Double mymoney=0;
Double FristValue=0;
Double SecondValue=0;
foreach(DataGridItem dgi in myDG.Controls[0].Controls)//.Items)
{
if (dgi.ItemType==ListItemType.Item||dgi.ItemType==ListItemType.AlternatingItem)
{
FristValue=Convert.ToDouble(dgi.Cells[FristCell].Text);
if (SecondCell==0)
{
SecondValue=1;
}
else
{
SecondValue=Convert.ToDouble(dgi.Cells[SecondCell].Text);
}
mymoney+=FristValue*SecondValue;}
if (dgi.ItemType==ListItemType.Footer)
{
if (mytablename!="T_Q_OP")
{
D_L_TotalPrice+=mymoney;//合计价钱
}
((Label)dgi.Cells[myDG.Columns.Count-1].FindControl("total_price")).Text=mymoney.ToString();
}
}
}
你在page_load中是否绑定了DataGrid,如果是
就在代码放在
if(!IsPostBack)
{
//databind code
}
{
CheckBox checkbox=(CheckBox)DataGrid1.Items[i].FindControl("GroupId");
if (checkbox.Checked)
{
}
}
我修改后的代码!
private void Button2_Click(object sender, System.EventArgs e)
{
for(int i=0;i<=DataGrid1.Items.Count;i++)
{
CheckBox MyCheck=(CheckBox)DataGrid1.Items[i].Cells[2].FindControl("GroupId");
if(MyCheck.Checked)
{
Label1.Text=MyCheck.Text;
}
else
{
Label1.Text="0";
}
}
}
foreach(DataGridItem item in AppGrid.Items )
{
if(((CheckBox)item.FindControl("CheckBox2")).Checked)
//proccess code
//if(((CheckBox)item.Cells[3].FindControl("CheckBox2")).Checked)
j++;
}
2.应用allanyan(allan) 的写法。
现在终于有了一点成果,那就是,只有选择最后一行的时候label1得值才有显示,而选择其他的没有反应,这又是什么毛病???
private void btnUpdate_Click(object sender, System.EventArgs e)
{
// Loop through the items in the datagrid.
foreach (DataGridItem di in dgContacts.Items)
{
// Make sure this is an item and not the header or footer.
if (di.ItemType == ListItemType.Item || di.ItemType == ListItemType.AlternatingItem)
{
// Get the current row for update or delete operations later.
DataRow dr = _dsContacts.Tables["Contact"].Rows.Find(dgContacts.DataKeys[di.ItemIndex]); // See if this one needs to be deleted.
if (((CheckBox)di.FindControl("chkDelete")).Checked)
{
_dsContacts.Tables["Contact"].Rows.Remove(dr);
}
else
{
// Update the row instead.
dr["Email"] = ((TextBox)di.FindControl("Email")).Text;
dr["FirstName"] = ((TextBox)di.FindControl("First")).Text;
dr["LastName"] = ((TextBox)di.FindControl("Last")).Text;
}
}
} // Save the changes if there are any.
if (_dsContacts.HasChanges())
{
SaveContacts();
} BindContacts();
}
DelId="delete groups where groupid=" + MyCheck.Text.ToString();
MyMcgsClass.Mcgs_DataConnOpen("../bbsdb.mdb");
OleDbCommand Mcgs_GroupDel=new OleDbCommand(DelId,MyMcgsClass.Mcgs_OleDbConn);
Mcgs_GroupDel.ExecuteNonQuery();
又删不掉数据了