Set initial combobox selection DevExpress Razor - razor

I simply want to have the "Area" value (which is one of the items) be selected when the view appears. This is what I have:
#Html.DevExpress( ).ComboBox( settings =>
{
settings.Name = "cmbFieldLevel";
settings.CallbackRouteValues = new { Controller = "Equipment", Action = "FieldLevelPartial" };
settings.Properties.ValueType = typeof( string );
settings.Properties.TextField = "AreaName";
settings.Properties.ValueField = "AreaID";
settings.Properties.EnableClientSideAPI = true;
settings.ClientSideEvents.DataBound = "function( s, e ){ cmbFieldLevel.SelectedItem = "Area"; } ";
}).BindList(FieldLevel.GetAreaFilters()).GetHtml()
Any clues?

2 ways I can think of.
If you change your ComboBox to ComboBox for you can specify the model's value
like so
#Html.DevExpress().ComboBoxFor(x => x.ParamOrderNo, settings =>
{
settings.Properties.ValueField = "OrderNo";
settings.Width = 200;
settings.Properties.TextField = "Name";
}).BindList(CeduleProductionMVC.ViewModels.ViewModelCeduleGlobale.GetCommandes()).GetHtml()
Also, you can set the SelectedIndex, if your combolist content is fixed, the index might always be the same everytime all the time. Also, If you list is not fixed, you might be able to make a method to retrieve the index and set in after that.

Related

add into selectlist an item only if it doesn't exist into razor

I want to create selectlist dynamically by traversing child nodes with 'language' property. So, want to add this property value as a select list item only if it is not added previously.
I have following code.
#{
var litem = new List<SelectListItem>();
litem.Insert(0, new SelectListItem { Selected = true, Text = "All", Value = "" });
foreach (var i in Model.Content.Children.Where("Visible"))
{
//if (i.GetProperty("language").Value != "")
if (i.GetProperty("language").Value != "")
{
string langstr = i.GetProperty("language").Value.ToString();
SelectListItem item = new SelectListItem { Selected = false, Text = langstr, Value = langstr };
if ((!(litem.Contains(item))))
{
litem.Add(item);
}
}
}
var slang=new SelectList(litem);
#Html.DropDownList("drpLang", #slang, new { #class = "dropdown"})
}
But it is not able to check the same item present in list. What is going wrong?
if i understand you correctly, problem that litem contain duplicate,
this because you create new instance of object item and than check is list contain new instance (you not check for same property, you check for exactly same object).
change this line:
if ((!(litem.Contains(item))))
for something like this:
if (litem.All(i => i.Value != item.Value))
or if you need unique pair:
if (litem.All(i => i.Value != item.Value && i.Text!= item.Text))
also recommend move all login in controller and use viewbag for DropDownList

How to get a Flag property from email message?

Can I somehow get a Flag property from EmailMessage or Item object? There is no getFlag() method, I also didn't find it in item.getPropertyBag(). I'm using ews-java-api-2.0. flag setting on outlook web app
There is a strongly type flag property in EWS in 2013 and greater so you could modify the EWS Java source to cater for that. Otherwise if you use the underlying Extended properties you can get the same information eg
ExtendedPropertyDefinition PR_FLAG_STATUS = new ExtendedPropertyDefinition(0x1090, MapiPropertyType.Integer);
ExtendedPropertyDefinition FlagRequest = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Common, 0x8530, MapiPropertyType.String);
PropertySet fiFindItemPropset = new PropertySet(BasePropertySet.FirstClassProperties);
fiFindItemPropset.Add(FlagRequest);
fiFindItemPropset.Add(PR_FLAG_STATUS);
FolderId FolderToAccess = new FolderId(WellKnownFolderName.Inbox, MailboxToAccess);
ItemView ivItemView = new ItemView(1000);
ivItemView.PropertySet = fiFindItemPropset;
FindItemsResults<Item> FindItemResults = null;
do
{
FindItemResults = service.FindItems(FolderToAccess, ivItemView);
foreach (Item itItem in FindItemResults.Items)
{
Console.WriteLine(itItem.Subject);
Object FlagValue = null;
if (itItem.TryGetProperty(FlagRequest, out FlagValue))
{
Console.WriteLine("Flag : " + FlagValue);
}
Object PR_FLAG_STATUS_Value = null;
if (itItem.TryGetProperty(PR_FLAG_STATUS, out PR_FLAG_STATUS_Value))
{
Console.WriteLine("PR_FLAG_STATUS : " + PR_FLAG_STATUS_Value);
}
}
ivItemView.Offset += FindItemResults.Items.Count;
} while (FindItemResults.MoreAvailable);
Theres a full list of flag properties https://msdn.microsoft.com/en-us/library/ee201258(v=exchg.80).aspx

How to get value of selected index in combo Box when user select the value from it in flex

Hi I have created a comboBox dynamically and Since I'm new to Flex I have no idea how to get the selected value from combo box when user select a value from combobox dropdown
Below is my code
var comboBox:ComboBox = new ComboBox();
comboBox.dataProvider = field.getValues();
comboBox.width = "50";
comboBox.prompt = "Test";
comboBox.selectedIndex = -1;
Could someone help me out in order to identify how I'll be able to get value of a selected index when user will select the value from dropdown of combo box ?
Even a sample example will help me !!
Thanks in Advance.....!!
You can use comboBox.selectedItem.
Remember to check for null as selectedItem will return null if it is not set.
comboBox.addEventListener(ListEvent.CHANGE, comboBox_change, false, 0, true); //weak listener
private function comboBox_change(event:Event):void {
var comboBox:ComboBox = event.target as ComboBox
var item:MyClass = comboBox.selectedItem as MyClass
if(item) {
//do what you need to do
}
}
You can do like following way:
var comboBox:ComboBox = new ComboBox();
comboBox.dataProvider = field.getValues();
comboBox.width = 50;
comboBox.prompt = "Test";
comboBox.selectedIndex = -1;
comboBox.addEventListener(ListEvent.CHANGE, onChange);
panel.addChild(comboBox);
private function onChange(event:Event):void
{
trace(event.currentTarget.selectedItem); //Here you get the selected item.
}
Hope it helps.

DropDownListFor selected value not working

So I have this in my view(I have broken it out into a foreach so I could debug it properly). And according to the objects that are created it looks good. I get 1 item that has the selected true.
#{
var useritems = new List<SelectListItem>();
foreach (var si in Model.UserList)
{
if (Model.CurrentUser.Id.Equals(si.Id))
{
useritems.Add(new SelectListItem { Selected = true, Text = si.Username, Value = si.Id.ToString(CultureInfo.InvariantCulture) });
}
else
{
useritems.Add(new SelectListItem { Text = si.Username, Value = si.Id.ToString(CultureInfo.InvariantCulture) });
}
}
}
What I want to do here is check for the current(logged on) user and set the select default to him/her.
#Html.DropDownListFor(model => model.Creator, useritems, new { id = "CreatorDDL", })
This does not however set any of the objects in useritems to selected. Even tho in the debugger it shows that 1 item has selected: true
Somehow it just shows the first item in the list.
Any ideas? or am I just tired and missing something really easy?
Set model.Creator value in addition to Selected in SelectList.
model.Creator = Model.CurrentUser.Id;
It's better to do such things in your Controller, not in your View.

Linq-2-Sql code: Does this scale?

I'm just starting to use linq to sql. I'm hoping that someone can verify that linq-2-sql has deferred execution until the foreach loop is executed. Over all, can someone tell me if this code scales. It's a simple get method with a few search parameters. Thanks!
Code:
public static IList<Content> GetContent(int contentTypeID, int feedID, DateTime? date, string text)
{
List<Content> contentList = new List<Content>();
using (DataContext db = new DataContext())
{
var contentTypes = db.ytv_ContentTypes.Where(p => contentTypeID == -1 || p.ContentTypeID == contentTypeID);
var feeds = db.ytv_Feeds.Where(p => p.FeedID == -1 || p.FeedID == feedID);
var targetFeeds = from f in feeds
join c in contentTypes on f.ContentTypeID equals c.ContentTypeID
select new { FeedID = f.FeedID, ContentType = f.ContentTypeID };
var content = from t in targetFeeds
join c in db.ytv_Contents on t.FeedID equals c.FeedID
select new { Content = c, ContentTypeID = t.ContentType };
if (String.IsNullOrEmpty(text))
{
content = content.Where(p => p.Content.Name.Contains(text) || p.Content.Description.Contains(text));
}
if (date != null)
{
DateTime dateTemp = Convert.ToDateTime(date);
content = content.Where(p => p.Content.StartDate <= dateTemp && p.Content.EndDate >= dateTemp);
}
//Execution has been defered to this point, correct?
foreach (var c in content)
{
Content item = new Content()
{
ContentID = c.Content.ContentID,
Name = c.Content.Name,
Description = c.Content.Description,
StartDate = c.Content.StartDate,
EndDate = c.Content.EndDate,
ContentTypeID = c.ContentTypeID,
FeedID = c.Content.FeedID,
PreviewHtml = c.Content.PreviewHTML,
SerializedCustomXMLProperties = c.Content.CustomProperties
};
contentList.Add(item);
}
}
//TODO
return contentList;
}
Depends on what you mean with 'scales'. DB side this code has the potential of causing trouble if you are dealing with large tables; SQL Server's optimizer is really poor at handling the "or" operator in where clause predicates and tend to fall back to table scans if there are multiple of them. I'd go for a couple of .Union calls instead to avoid the possibility that SQL falls back to table scans just because of the ||'s.
If you can share more details about the underlying tables and the data in them, it will be easier to give a more detailed answer...