如何在mvc 4实体框架中将值绑定到checkboxfor?

时间:2016-01-28 06:18:38

标签: c# entity-framework model-view-controller

这是我的模特。

   FrmProcessOrder _FrmProcessOrder;
    public FrmSelection()
    {
        InitializeComponent();

        LoadData();
    }

    //Method which reads data from the db and laod data on listview
    public void LoadData()
    {
        _connection = "Data Source=MILESTONE-PC;Initial Catalog=Jack;Integrated Security=True";
        _sql = "Select * from tblJackon";
        _conn = new SqlConnection(_connection);
        _conn.Open();

        _comm = new SqlCommand(_sql, _conn);
        _adapt.SelectCommand = _comm;
        _adapt.Fill(_dataset, _sql);
        DataTable _tbl = _dataset.Tables[0];
        _dtrow = null;

        foreach (DataRow _dataVariable in _tbl.Rows)
        {
            _dtrow = _dataVariable;
            ListBoxSelection.Items.Add((_dtrow["FormNames"]));
        }
    }

    private void btnAddForms_Click(object sender, EventArgs e)
    {
        _FrmProcessOrder.AddList(ListBoxSelection);  // It throws error on this line after select from listbox so that the item must to FrmProcessOrder listbox
        _FrmProcessOrder = new FrmProcessOrder();    
    }

我想将ScreenName绑定到控件的复选框。在db我有数据。我想绑定。 我改变了这样的事情

这是控制器代码。

public partial class Tm_Screen
    {
        public int Screen_Id { get; set; }
        public string Screen_name { get; set; }
        public string Screen_Desc { get; set; }
        public string IsActive { get; set; }
   }

这是观看代码

 var list = new List<tm_scrn_screen>
                   {
                       new tm_scrn_screen{scrn_name="csscs",scrn_isactive=true}
                   };

                return View( list);

这不起作用。 一些红色标记接近m =&gt;米[I] .scrn_name

1 个答案:

答案 0 :(得分:0)

CheckBox主要用于表示单个布尔字段。如果您希望它显示值列表并让用户检查多个值,则需要自定义代码。通常方式是多选无复选框列表。但如果您需要,可以找到多个实现thisthisthis。只需谷歌,你会发现很多例子