I can't bind data to combobox, pls help me, it just show a blank combobox
My models
public class DanTocModels { [Key, Required, MaxLength(8)] public string MaDanToc{get;set;} public string TenDanToc { get; set; } }}
[controller] I used to Dapper(name of controller is: CommonController) and this below is my function
public IEnumerable get_all_dan_toc() { var rs = SqlMapper.Query(cn, "select * from tbl_dan_toc order by MaDanToc asc"); return rs; }
[view]
@model
@(Html.Infragistics().ComboFor(item => item.MaDanToc) .Width("270px") ..DataSource(Url.Action("/common/get_all_dan_toc")) .ValueKey("MaDanToc") .TextKey("TenDanToc") .DataBind() .Render() )
Tk Denis Georgiev I can load all data for combobox but I have problem when set select item for combobox.
I can't used method .SelectedIndexes(int[]) it have error Error 9 'Infragistics.Web.Mvc.ComboWrapper' does not contain a definition for 'SelectedIndexes' and no extension method 'SelectedIndexes' accepting a first argument of type 'Infragistics.Web.Mvc.ComboWrapper' could be found.
And how to use Html.Infragistics().ComboFor() at mvc view, I have some code below
class PersonModels
{
string Fullname {get;set;}string CityID {get;set;}
...
}
if string someone person CityID has values 2 how to set selected item when I load all combobox city with city name & values
I use Dapper with return detail of someone person like this
[repository]
public List<PersonModels> Details(string id) { var p = new DynamicParameters(); p.Add("PersonID", id); IList<PersonModels> person = SqlMapper.Query<PersonModels>(cn, "proc_TS_ThongTinTuyenSinhLoadByPrimaryKey", p, commandType: CommandType.StoredProcedure).ToList<PersonModels>(); return person.ToList(); }
how to set selected item for combobox city from Person CityID value
Hello Quang,
Please provide sample replicating your issue.
Sr Denis Georgiev, maybe not clearly with my questions, let me tell you more details, I have a small app manage profiles students (asp mvc), when I create a new profile: I can load all data combobox and allow user select state or country, but this is my problem when edit a profile I can't set selected values for combo country/state which I had been choosen before.
this is link to my code: https://www.fshare.vn/file/454TL96S9KT6
You can set combo mode to be dropdown list.
Then you can set initialSelectedItems.
For more refer to the attachment.
It's ok, I can set selected items in view by javascript here is my code:
$('#combo').igCombo({ initialSelectedItems: [{ index: 0 }] });
but my problem is I can't figure out how to set selected combobox with value (not index) from code behind in controller and return it to view.
Can I use combobox like this : List items = new List() and have selected if compare = true on value
foreach (countryModels)
items.Add(new SelectListItem { Text = ct.countryID.ToString().Trim() + " | " + ct.countryname.Trim() ,Value = ct.countryID.ToString().Trim() ,Selected = (ct.countryID.ToString().Trim() == CountryId) });
[controller]
ViewBag.List_Country=items;
Call combobox with have selected value from controller
Tk again