遍历控件最简便的方法??
做N个CheckBox,CheckBox的Name是数据库中列的名称,Text则是要在GirdView中的列名代码如下 希望大家给兄弟点思路
--------------------编程问答-------------------- 可以了,你还想怎样 --------------------编程问答-------------------- 如果是checkbox 取他的name和text 拼接一个sql查询 --------------------编程问答-------------------- 已经是这样了
EmployeeName.Name = EmployeeName; //EmployeeName 是 CheckBox
EmployeeName.Text = 姓名;
EmployeeSex.Name = EmployeeSex;
EmployeeSex.Text = 性别;
string strsql = "select ";
string strsql2 = "from person";
foreach(Control c in this.Controls)
{
if (c is CheckBox)
{
}
}
你还想怎么遍历
--------------------编程问答-------------------- 补充在被选中的情况下 取他的name和text 拼接一个sql查询 --------------------编程问答-------------------- 就在sql语句中调用它们的值就好了啊 --------------------编程问答-------------------- 调用会啊 拼接起来 没思路啊
string str ;
string sql = "select ";
string sql2 = "from 表";
SqlDataAdapter sda = new SqlDataAdapter(sql+ str+ sql2,con);
DataSet ds = new DataSet();
sda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
foreach (Control c in this.Controls)
{
switch (c is CheckBox)
{
case EmployeeID.Checked:
str = EmployeeID.Name + " as " + EmployeeID.Text;
case EmployeeName.Checked:
str = EmployeeName.Name + " as " + EmployeeName.Text;
}
}
--------------------编程问答--------------------
switch (c is CheckBox)--------------------编程问答-------------------- if(c is CheckBox)
{
CheckBox cb= c as CheckBox;
case cb.Checked:
//logic code
}
{
//拼接sql 语句,执行你的操作
补充:.NET技术 , C#