代码片段

1.grid判断查看哪一行的CheckBox被选中      

foreach(GridViewRow row in this.StudentGridView.Rows)
        {
            Control ctrl = row.FindControl("CheckBox");
         
                if ((ctrl as CheckBox).Checked)
                {
                    TableCellCollection cell = row.Cells;
                    string studentCode = cell[1].Text;
                 }                
         }

 

2.递归

 

// 清空控件内容
private void ClearText(Control ctr) {
    for (int i = 0; i < ctr.Controls.Count; i++) {
        // 若当前控件内部包含其他控件则继续遍历
        if (ctr.Controls[i].Controls.Count > 0) {
            ClearText(ctr.Controls[i]);
        } else {
            // 判断控件类型,做相应处理
            if (ctr.Controls[i] is TextBox) {
                TextBox txt = null;
                txt = ctr.Controls[i] as TextBox;
                txt.Text = string.Empty;
            } else if (ctr.Controls[i] is ComboBox) {
                ComboBox cbo = null;
                cbo = ctr.Controls[i] as ComboBox;
                cbo.Text = string.Empty;
            }
        }
    }
}
posted @ 2012-02-27 14:36  DODUI  阅读(186)  评论(0编辑  收藏  举报