private void PopulateMinistires() { SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings [ConnectionString]); conn.ConnectionString =数据源= USER-PC;初始目录= PIWCDB;用户ID = sa;密码=迈克; 使用(SqlCommand cmd = new SqlCommand()) { cmd.CommandText =select * from tblMinistries; cmd.Connection = conn; conn.Open(); using(SqlDataReader sdr = cmd.ExecuteReader()) { while(sdr.Read()) { ListItem item = new ListItem(); item.Text = sdr [Homecellname]。ToString(); chkMinistries.Items.Add(item); } } conn.Close(); } }
解决方案
Richard C. Bishop的解决方案1可能对您有所帮助,但如果没有,请参考:无法找到类型或命名空间名称\’ListItem\’ [ ^ ]。为Web窗体添加此内容:
使用System.Web.UI.WebControls;for Win Forms:
使用System.Windows.Forms;到顶部您的页面或使用完全限定的名称对于控件。
嗨Mike,请看这些例子: 使用DataBase绑定CheckBoxList [ ^ ] 使用CheckBoxList填充 [ ^ ] 问候。
i have a table in my mssql db with 2 columns (homecellid and homecellname) i want all data in homecell to be displayed in a checkboxlist (cblMinistries) i tried this but i keep getting an error \”The type or namespace name \”ListItem\” could not be found\” please help me out
private void PopulateMinistires() { SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings[\”ConnectionString\”]); conn.ConnectionString = \”Data Source=USER-PC;Initial Catalog=PIWCDB;User ID=sa;Password=mike\”; using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = \”select * from tblMinistries\”; cmd.Connection = conn; conn.Open(); using (SqlDataReader sdr = cmd.ExecuteReader()) { while (sdr.Read()) { ListItem item = new ListItem(); item.Text = sdr[\”Homecellname\”].ToString(); chkMinistries.Items.Add(item); } } conn.Close(); } }
解决方案
Solution 1 by Richard C. Bishop might help you, but if not, please, refer this: The type or namespace name \’ListItem\’ could not be found[^].
Either add this for Web Forms:
using System.Web.UI.WebControls;of this for Win Forms:
using System.Windows.Forms;to the top of your page or use the fully qualified name for the control.
Hi Mike, see these examples: Bind CheckBoxList with DataBase[^] Populate with CheckBoxList[^] Regards.