MVC :: DropDownList Helper And SelectListItem Selected Property Being Ignored?
Jul 6, 2010
I am producing a List(Of SelectListItem) from my database and passing this to a DropDownList Html Helper method on my View via the controller.This works ok but I seem to have found a bug or issue where the DropDownList ignores the Selected property of the SelectListItem objects in the list.I have a provider class in my model which will read the database, create the List(Of SelectListItem) and then depending on whether or not the user is associated with one of the options, I will set the Selected property to True for that item.
code]...
View 16 Replies
Similar Messages:
Mar 7, 2011
how to make a item the default from a dropdownlist, I want to make the value GBP as the option selected when the page loads, i've spent all day trying to get ddlist to work and now i'm stuck on this.
this
.ViewData["ddlCurrency"]
= new
SelectList(ws.ToList(),
"dboCurrencyID",
"dboCountry",
new
SelectListItem
{ Selected = true,
Text = "United
Kingdom (GBP)", Value =
"GBP"
});
View 1 Replies
Jan 25, 2011
Is there a way to retrieve the client side ID for a model property similar to how the helpers like LabelFor etc generate the ID? For example, I have a model with a DateOfBirth property. I want to hook up that field to a jQuery DatePicker. Normally, I would hook up the date picker like this:
[Code]....
This works fine but hard codes the DateOfBirth property name. Ideally, I would like to use this:
[Code]....
Is this already available out of the box somewhere? I just created an extension method on the HtmlHelper class that does exactly this, but I wondered if there was already something built-in so I don't have to reinvent and test the wheel.
View 10 Replies
Apr 22, 2010
The strongly typed helpers are now written like this -
<%= Html.TextBoxFor(model => model.State) %>
I need to add a default value to a textbox. In the prior version of Asp.Net MVC it was easy to assign a default value. I thought doing the following would work in MVC 2-
<%= Html.TextBoxFor(model => model.CountyId, new{ value = 840 })%>
This, however, does not work for me in Asp.Net MVC 2. The value is still blank for the textbox. I want to make sure that this isn't some random error that I am having. Has anyone else encountered the same problem? I have searched and searched to find more information on the default property for the html helpers in MVC 2, but I can't find anything. Does anyone out there know how to correctly assign a default value to a textbox in Asp.Net MVC 2?
View 3 Replies
Sep 22, 2010
I have created a CheckBoxList and a CheckBoxListFor helpers that I am using as follows:
[Code]....
[Code]....
What am I doing wrong? I think in CheckBoxListFor I might get the u.Roles values and fill the SelectList selected items if they don't match?
View 9 Replies
Apr 23, 2010
Example: I create a custom type in my domain model (say a "Country" class with Id and Text fields)
A "Person" object have a property of the above type.
The Service class return a list of Countries (IEnumerable<Country> GetCountries();)
Now the ViewModel, derive from the "Person" object and have a member "Countries" which is IEnumerable<SelectListItem> Countries (It convert the Country collection from the service to a collection of SelectListItems.
I use the SelectLIst collection to populate my dropdown.
However when I submit the form, validation fail, obviously because the "Country" dropdown give a string value, while a Country object is expected.
So I need to cast this value from a string (using the "id" of the SelectListItem) to a Country object.
Where and how would be the right way to do this? (Another late night with me bing brain dead and probably overlooking the obvious).
View 4 Replies
Apr 24, 2010
Perhaps should have posted this with my previous question, but now that I figured the problem, it might be better to create a new one.
My viewmodel is a custom type (say Person) and one of it's members another custom type (say "EmploymentStatus").
I got a list of "EmploymentStatuses" which I convert from IEnumerable<EmploymentStatus> to a SelectList
[Code]....
and I use this list in my View (Strongly typed using PersonModel)
[Code]....
All fine. The problem is that my controller expect a person object and when it does validation, it tell me that the employment status selection are not valid. Obviously because a EmploymentStatus object are expected whereas the View return a SelectListItem.
View 2 Replies
Apr 15, 2010
I am having a problem with disabling DropDownList based on the chice of 1st DropDownList, there is no post back occuring, and it is a template based web app here is the current code:
<script type="text/javascript">
$(function() { var dropDownList1 = $('#<%= ddlUserType.ClientID %>');
var dropDownList2 = $('#<%= ddlMember.ClientID %>'); dropDownList1.change(function(e) {
if ( jQuery("#ddlUserType").val() != "ETOC") dropDownList2.removeAttr('disabled'); e.preventDefault();
else
dropDownList2.removeAttr('enabled'); e.preventDefault(); }
} );
</script>
what is happening now is page is blank and if I remove the above code everything shows, where I am going wrong. here is the plain and final javascript code which worked:
<script language="javascript">
function CheckDropDownState(lstbox)
{
if (lstbox.selectedIndex == 3) { document.forms[0].ddlMember.disabled = 1; }
else { document.forms[0].ddlMember.disabled = 0; }
}
</script>
and thew .aspx code: <asp:dropdownlist id="ddlUserType" runat="server" onclick="CheckDropDownState(this);"></asp:dropdownlist>
View 2 Replies
Sep 6, 2012
protected void DDLzone1_SelectedIndexChanged(object sender, EventArgs e)
{
BindDistrict();
}
[Code]......
here when i click on ALL item from ddlzone1 it just "ALL" item in ddldistrict
i want when i select "ALL" item from ddlzone1 in ddldistrict14 show all data from database
View 1 Replies
Jan 11, 2011
what i m trying is i hav two dropdownlists inside the gridview... namely say ddonsiteoffsite and ddhours... now what i want is if the selectedtext of ddonsiteoffsite is "onsite" the ddhours should b disabled... i tried the code snippet but ... its not disabling the ddhours... can someone help me please..
<asp:TemplateColumn HeaderText=" OnSite/OffSite" >
<ItemTemplate>
<asp:DropDownList ID="ddOnsiteOffside" runat="server" onchange="ToggleOnOff(this)">
[code].....
View 2 Replies
Dec 17, 2012
I am having a 2 dropdown list, in the first dropdown I have 3company names,for each company I am having separate tables,every table have a empcode, if the user select the company name in the 1st dropdownlist, as per company selected the 2nd dropdownlist it will fill the list of employee codes as per the selection..
View 1 Replies
May 7, 2015
I have two pages manager and user both have drop downs as
Week, Months and Years.
User have to enter some data week wise for each months and Manager have to approve that.
To Approve manager select months and week from dropdown on his own page and then navigate to User page.
How does I should bind the drop down so that if manager select 1st week from it's page and goes to view link of user then in drop down of user selected value shold be the same as selected by Manager on his own page.
View 1 Replies
Nov 26, 2010
I am binding months to a list 0-13 items default selection is 0 months duration, and years 0-8 items and 0 years is the default selection.As I know there are always going to be 12 months in a year, I could use selectedvalue or selectedindex without any perceived problem. Is there a reason why I should not use either/or of the two properties to select a list item?
View 2 Replies
Mar 9, 2010
I have a main "index" view that has a drop down and a submit button. When a selection is made (CampaignId) and a submit button is pressed a list of items is displayed and filtered based on the selection from the drop down list.
I've added a partial view (on the right rail) of my site that lists a bunch of campaigns. when a link is pressed in that partial view a (CampaignId) is passed to my page and the same thing happends as if you would make a selection from the drop down. The issue is that the dropdown "Campaign Name" should be selected based on the selection from the partial view.
[code]....
View 1 Replies
Oct 6, 2010
I am trying to make a simple dropdownlist.Based off what is selected as the dropdownlist, I want it to open a new webpage.
For example:
Here is the dropdownlist - If they select team1, I want it to open up webpage /team1.aspx If it's team2, team2.aspx and so on.
<form id="form1" runat="server">
View 2 Replies
Feb 2, 2010
I have a web user control (ascx) that exposes an "ID" property. What I want to do is set this property when the SelectedIndexChanged event fires in a gridview in the containing page. However, I can't seem to do it.... Here's my code:
protected void grdPhysicians_SelectedIndexChanged(object sender, EventArgs e)
{
physicians_certif1.mdID = grdPhysicians.SelectedDataKey.ToString();
mvData.SetActiveView(viewEdit);
panAdditional.Visible = true;
}
Physicians_certif1 is the user control. It seems the user control is loading before the SelectedIndexChanged event has a chance to set it's property.
View 2 Replies
Aug 23, 2010
I am using LINQ-to-Entities and here is my query
public void SomeFunction(string searchField)
{
var data = from a in dx.SomeTable where [code]...
Now if I had to use the value of the parameter "searchField" as the property to be selected in the where clause then how do I do it ?
i.e I want to assign the value of the parameter "searchField" to the property I am checking in the where clause.
So ... the value of "SomeProperty" in a.SomeProperty must be the value of "searchField". How to do this ?
PS : I dont want a.SomeProperty=searchField. What I want is "SomeProperty" itself to be replaced by the value of "searchField" and then , this has to be checked to see if its equal to 270.
View 2 Replies
Dec 29, 2010
I have a CheckBoxList. I want to select checkboxes then calculate a total price for the items selected. The datasource for the CheckBoxList is a join of two tables and contains the information I want to retrieve. The DataTextField = ItemName and DataValue = ItemPrice. Code behind is C#.
Is there a SUM Selected items property for a CheckBoxList?
View 6 Replies
Sep 30, 2010
I thought this would be pretty simple, and in fact it's working on another dropdownlist on the same View, so I'm hoping I missed something very small that is easy to fix. Here's my code:
[Code]....
When I step through the code, the 'Active' option's 'Selected' property is being set to true. That's expected. But when the View renders, it's not selected and a look at the page source shows that the selected property isn't set. What is the problem here, and what's the solution?
View 10 Replies
Oct 1, 2010
if the menuitem included a navigateUrl , selected property does not work. Have anyone encounter the same problem as well? what I want is selected a menu item, and asp.net bring to some page with the selected menu item's color changed.
View 2 Replies
Jul 2, 2010
I have a combox box inside a dataform which is bound to riacontrol's datadomainsource say "x" and data form is bound to riacontrol's datadomainsource say "y". Now when I am submiting change then I am not able to find the selected value for the combo box for dataform's data property. It is showing 0 to me.
View 2 Replies
Jan 6, 2011
how to retrieve the selected row cell value if it is visible property is false in gridview?
View 1 Replies
May 3, 2010
I am displaying a table into a gridview for which I've a SQL query written which uses IF-ELSE condition. In one of the conditions, if the condition stands TRUE then one of the coloms should be eliminated from the table. But I constantly get an error:"A field or property with the name 'IXC_Vendor_Circuit_ID' was not found on the selected data source."
View 6 Replies
Oct 26, 2010
I'm trying to set a property on a custom DropDownList:
<custom:ReferenceDropDownList ... ValidityDate="<%# Application.CreateDate %>" />
Even though I can see that Application.CreateDate has been set in the Page_Load method on the containing UserControl, the code-behind in the DDL never seems to pick it up.
protected override void OnLoad(EventArgs e)
{
// this.ValidityDate is always null
}
This is even the case with ValidityDate="<%# DateTime.Now %>". The property of the DDL is declared like this:
[Category("Data")]
[DefaultValue(null)]
public DateTime? ValidityDate { get; set; }
what is the correct sequence I should be following here. I thought that a DDL would evaluate a cynamic property value like that without too much trouble.
View 1 Replies
Oct 1, 2010
[Code]....
View 1 Replies