如何在单个列中获取总复选框并将其显示为标签 [英] How to get the total checked checkbox in a single column and show it into a label

查看:54
本文介绍了如何在单个列中获取总复选框并将其显示为标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我需要一些帮助。我搜索了大多数网站,但没有为我的查询找到所需的代码。

我正在编写窗口应用程序中的出席班级模块,这里我有一个有学生姓名的gridview(文本框列) ,滚动否(文本框列),存在(复选框列),缺席(复选框列),休假(复选框列)。

1)我只想连续检查一个复选框。

2)我想在标签名称总现在学生中显示当前学生总数(表示总共当前复选框列复选框)。



这是我的保存按钮点击事件,用于将值保存到表格中。

Hello,
I need some help. I searched mostly sites but did not find desired code for my query.
I am coding for a module of "Attendance of Class" in window application and here I have a gridview having student name(textbox column), roll no(textbox column), present(checkbox column), absent(checkbox column), on leave(checkbox column).
1) I want only one checkbox should be checked in a row.
2) I want to show the total present student(means total of "present checkbox" column checked checkboxes) in a label names total present students.

Here is my "Save Button" click event to save the values into the table.

private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                SqlDataAdapter da = new SqlDataAdapter("Select Date FROM tbAttendance WHERE Date='"+dtpDate.Value+"'", con);
                DataTable dt = new DataTable();
                da.Fill(dt);
                if (dt.Rows.Count > 0)
                {
                    MessageBox.Show("Attendance Already Added, Please Select another Date for this Class and Section");
                }
                else
                {
                    if (cbClass.SelectedIndex != 0 && cbSection.SelectedIndex != 0)
                    {
                        con.Open();
                        for (int i = 0; i < dgvAttendance.Rows.Count - 1; i++)
                        {
                                SqlCommand cmd = new SqlCommand("Insert into tbAttendance VALUES('" + dgvAttendance.Rows[i].Cells["Student_id"].Value + "', '" + dtpDate.Value + "', '" + dgvAttendance.Rows[i].Cells["Present"].Value + "', '" + dgvAttendance.Rows[i].Cells["Absent"].Value + "', '" + dgvAttendance.Rows[i].Cells["Leave"].Value + "', '" + dgvAttendance.Rows[i].Cells["Remarks"].Value + "')", con);
                                cmd.ExecuteNonQuery();
                                MessageBox.Show("Successfully submited");
                        }
                        con.Close();
                    }
                    else
                    {
                        MessageBox.Show("Please Select Class and Section");
                    }
                }
            }
            catch (Exception)
            {
                
                throw;
            }
        }





任何建议都将不胜感激。在此先感谢



Any Suggestion would be appreciated. Thanks in advance

推荐答案

您是否知道WinForms CheckBox可以选择具有三个'CheckState值?



CheckState.Checked

CheckState.UnChecked

CheckState.Indeterminate



要将CheckBox用于三种状态,请将ThreeState属性设置为true。所以,你可以用一个Control来处理present,absent和on leave,而不是三个。



其次,你可以使用RadioButtons,而不是CheckBoxes,用于建模互斥状态,这是您的应用程序现在使用CheckBoxes的方式。为什么编写代码以确保只检查一个CheckBox,使用RadioButtons时会免费给你?



2)我想要显示总现在学生(表示共有当前复选框列复选框)在标签中列出当前学生总数。



您没有显示执行此操作的任何代码,但这很简单:到目前为止你尝试了什么?
Are you aware the WinForms CheckBox can, optionally, have three 'CheckState values ?

CheckState.Checked
CheckState.UnChecked
CheckState.Indeterminate

To use the CheckBox with three states, set the 'ThreeState Property to 'true. So, you could handle "present," "absent," and "on leave" with one Control, not three.

Second, you can use RadioButtons, rather than CheckBoxes, to model mutually exclusive states, which is the way your application uses CheckBoxes now. Why write the code to make sure only one CheckBox is checked, when using RadioButtons will give that to you "for free" ?

"2) I want to show the total present student(means total of "present checkbox" column checked checkboxes) in a label names total present students."

You don't show any code for doing this, but it's pretty simple: what have you tried so far ?


这篇关于如何在单个列中获取总复选框并将其显示为标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆