How do I give my dropdownlist an id? - asp.net

Hi I tried examples on the site but can't find solution. I get no error but the id is not assigned to my dropdown list. How do I assign an id to this dropdown list?
#Html.DropDownList("searchString", Model.WeekDays.Select(s => new SelectListItem { Text = s.ToString(), Value = s.ToString(), Selected = s.ToString().Equals("Day") }), new { #id = "listId" })
Thanks for any help!

#Html.DropDownList("searchString", Model.WeekDays.Select(s => new SelectListItem { Text = s.ToString(), Value = s.ToString(), Selected = s.ToString().Equals("Day") }))
The first string argument in #Html.DropDownList is its id, remove the id u are giving as attribute.

try below code :-
#Html.DropDownList("searchString", Model.WeekDays.Select(s => new SelectListItem { Text = s.ToString(), Value = s.ToString(), Selected = s.ToString().Equals("Day") }), new { id = "listId" })

Related

Viewbag New Selectlist Placeholder

I have a simple select list being generated in my action method (code below)
Viewbag.Select = new SelectList(db.esp_admin_form_demographics.Where(x => x.category == (int) SelectHelper.ClientSelectOptions.Demographics.BirthCountry || x.category == 999), "id", "value", "");
How is it possible to add a placeholder value in there as the default value?
Here is the solution to set placeholder as the default value in your SelectList/DropDownList :
In the Controller Method:
var espAdminList = db.esp_admin_form_demographics.Where(x => x.category == (int) SelectHelper.ClientSelectOptions.Demographics.BirthCountry || x.category == 999)
Viewbag.EspAdminSelectList = new SelectList(espAdminList, "id", "value");
Then in the view:
#Html.DropDownList("EspAdminId",ViewBag.EspAdminSelectList as SelectList, "Select Esp. Admin", new { #class = "form-control" })

How to use notanyof in nlobjSearchFilter

var ids = ['1', '2', '3'];
var filters = new Array();
filters[0] = new nlobjSearchFilter('mainline', null, 'is', 'T');
filters[4] = new nlobjSearchFilter('entity', null, 'notanyof', ids);
var searchResult = nlapiSearchRecord('creditmemo', null, filters, columns);
Hello I'm trying to list all credit memos but where the customer ID is not 1,2 or 3?
Can you help me? Thanks
The proper operator is "noneof".
new nlobjSearchFilter('entity',null,'noneof',[1,2,3]);

Set Default Date with DropdownListFor using Enumerable Range

i'm trying set into dropdown's current date i'm tried many variants how to achieve this.. so here is my sample code..
#{ var days = Enumerable.Range(1, 31).
Select(i => new SelectListItem {Value = i.ToString(), Text = i.ToString(), Selected = i == DateTime.Now.Day}).ToList();
var month = Enumerable.Range(1, 12).
Select(i => new SelectListItem {Value = i.ToString(), Text = System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat.GetMonthName(i), Selected = i == DateTime.Now.Month}).ToList();
var years = Enumerable.Range(2000, DateTime.Now.Year - 2000 + 4).
Select(i => new SelectListItem {Value = i.ToString(), Text = i.ToString(), Selected = i == DateTime.Now.Year}).ToList();
}
#Html.DropDownListFor(model => model.SDay, days)
#Html.DropDownListFor(model => model.SMonth, month)
#Html.DropDownListFor(model => model.SYear, years)
as you can see i set Today in Selected option for day, month and year, debugger show me that today day is selected Debugger but on view day is set at 1

Html.DropDownListFor value not selected on edit mode

I am succesfullly able to save value to database (title value) on insert , but when i render the same view in edit mode then title field must hold the selected value but in my case no value is selected by title dropdown...dont know why i am getting a dropdown with nothing selected while title field holds the stored value(at backend).
#Html.DropDownListFor(model => model.title, new SelectList(Model.titles, "Value", "Text"),"-Select-") // nothing selected on edit mode
#Model.title //displaying the stored value which the user selected initially.
values for title
titles = new SelectList(ListItem.getValues().ToList(), "Value", "Text").ToList();
getValue function
public static List<TextValue> getValues()
{
List<TextValue> titles= new List<TextValue>();
TextValue T= new TextValue();
T.Value = "Mr";
T.Text = "Mr";
titles.Add(T);
T= new TextValue();
T.Value = "Mrs";
T.Text ="Mrs";
titles.Add(T);
T= new TextValue();
T.Value = "Miss";
T.Text = "Miss";
titles.Add(T);
T= new TextValue();
T.Value ="Other";
T.Text = "Other";
titles.Add(T);
return titles;
}
You've got to use another ctor of SelectList
From msdn
SelectList(IEnumerable, String, String, Object)
Initializes a new instance of the SelectList class by using the
specified items for the list, the data value field, the data text
field, and a selected value.
Then :
#Html.DropDownListFor(model => model.title,
new SelectList(Model.titles, "Value", "Text", Model.title),
"-Select-")
By the way, it's generally a good idea to follow basics standards (at least) : your properties should begin by an Upper case char.
public string Title {get;set;}
Views:
#Html.DropDownListFor(model => model.title, Model.titles, "-Select-")
Controllers:
Model.titles = new SelectList(ListItem.getValues(), "Value", "Text");
public static List<SelectListItem> getValues()
{
List<SelectListItem> titles= new List<SelectListItem>();
SelectListItem T= new SelectListItem();
T.Value = "Mr";
T.Text = "Mr";
titles.Add(T);
T = new SelectListItem();
T.Value = "Mrs";
T.Text = "Mrs";
titles.Add(T);
T = new SelectListItem();
T.Value = "Miss";
T.Text = "Miss";
titles.Add(T);
T = new SelectListItem();
T.Value = "Other";
T.Text = "Other";
titles.Add(T);
return titles;
}
public ActionResult Edit(int sno)
{
var model = db.table.SingleOrDefault(x => x.sno == sno);
return View(model);
}

Replace letter ي with letter ی in linq?

i want Replace بازي to بازی
var List = (from darkhast in Tbl_Darkhast.Where(d => d.Address.Replace("ی","ي").StartsWith( Address.Replace("ی","ي") ) )
select new
{
....
}
I think,You should write in select query
var List = (from darkhast in Tbl_Darkhast) )
select new Tbl_Darkhast
{
Address= darkhast.Address.Replace("ی","ي")
,Name = darkhast.Name
};
The distance and character displacement:
var List = (from darkhast in Tbl_Darkhast.Where(d => d.Address.Replace(" ", "").Replace("ي", "ی").Replace("ك", "ک").StartsWith(Address.Replace(" ", "").Replace("ي", "ی").Replace("ك", "ک")))
select new
{
....strong text
}
result is =>
var List = (from darkhast in Tbl_Darkhast.Where(d => d.Name_Moteghazi.Replace(" ", "").Replace("ي", "ی").Replace("ك", "ک").StartsWith(NameMoteghazi.Replace(" ", "").Replace("ي", "ی").Replace("ك", "ک")))
select new
{
Shomare_Darkhast = darkhast.Shomare_Darkhast,
Tarikhe_Darkhast = darkhast.Tarikhe_Darkhast,
Sharhe_NoeDarkhast = darkhast.TBL_NoeDarkhast.Sharhe_NoeDarkhast,
Mantaghe = darkhast.Mantaghe,
Hoze = darkhast.Hoze,
Block = darkhast.Block,
Melk = darkhast.Melk,
});
return (ObjectQuery)List;

Resources