将一些checklistbox项标记为已选中 [英] mark some checklistbox items as checked
本文介绍了将一些checklistbox项标记为已选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个窗口表单,它从表(tblMinistries)加载所有数据并将其显示在一个清单框中。这项工作正常,现在我有另一个表(tblNewministries),我希望表格中的所有项目(tblNewministries)在填充它时在checkedlistbox中自动检查。 table(tblNewministries)是表的一个子集(tblMinistries)
请帮帮我
代码
public void PopuMinistry22()
{
SqlConnection conn = new SqlConnection(Data Source = USER-PC; Initial Catalog = PIWCDB; User ID = sa; Password = mike);
if(conn.State!= ConnectionState.Open)
{
conn.Open();
}
string SqlDataPull =(通过Homecellname从tblministries顺序选择Homecellname);
SqlCommand cmd = new SqlCommand(SqlDataPull);
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
SqlDataPull = dr [0] .ToString();
cblMinistries.Items.Add(SqlDataPull);
}
dr.Close();
}
解决方案
如果您有复选框的id,那么您可以使用document.ready()中的jqury来执行此操作代码。
(' #myCheckbox')。prop(' checked',< span class =code-keyword> true );
(' #myCheckbox')。prop(' checked',假跨度>);
I have a windows form which loads all data from a table (tblMinistries) and displays it in a checklistbox. This work works correctly, now i have another table (tblNewministries) and i want all the items in the table (tblNewministries) to be checked automaticaly in the checkedlistbox when it is populated. table (tblNewministries) is a subset of table (tblMinistries)
Please help me out
code
public void PopuMinistry22() { SqlConnection conn = new SqlConnection("Data Source=USER-PC;Initial Catalog=PIWCDB;User ID=sa;Password=mike"); if (conn.State != ConnectionState.Open) { conn.Open(); } string SqlDataPull = ("select Homecellname from tblministries order by Homecellname"); SqlCommand cmd = new SqlCommand(SqlDataPull); cmd.Connection = conn; cmd.CommandType = CommandType.Text; SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { SqlDataPull = dr[0].ToString(); cblMinistries.Items.Add(SqlDataPull); } dr.Close(); }
解决方案
If you have id with checkboxes then you can do this using jqury in document.ready() by using the code.
('#myCheckbox').prop('checked', true);
('#myCheckbox').prop('checked', false);
这篇关于将一些checklistbox项标记为已选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文