I keep getting this error and i just can't figure it out:
The ViewData item that has the key 'CampaignId' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>'.
My Controller:
//show empty form
[AcceptVerbs(HttpVerbs.Get)]
public ViewResult Index(int? CampaignId)
[Code]....
I do need to have "CampaignId" in there because I'm populating some "partial views' based on this "CampaignId" that is selected (drop down)
I have a Drop Down List which I need to bind to the database. Here is the situation. I am not using a SQLDataSource. It is built on the n-tier application. The datasource of the dropdown is referring to a method in the C#class. That method has a generic array list which populates information into the arraylist. The Arraylist is the parameter that is returned to the DropDown List.
I have also set the Text property of the Drop down list
I have a table Person (in my database) which has fields like PersonID, PersonName, PersonSurname, etc. What I'd like to do is to bind the PersonName + PersonSurname (e.g. Mark Black) as values for displaying the data in drop down list and PersonID as the data identifier.
As I'm still new with Entity Framework I'm not sure how to manage to do it.
What I want is two drop down lists, one linked to /Levels/Level and one to the SubLevels for the selected level. Currently, I have the main one bound as follows:
I like ASP.NET MVC, because I like to have direct access to my web site's structure. However there's 1 thing that I don't like.
In Ruby on Rails to send data from Controller to View is really easy:
# Get a user in controller
@user = User.first(:id => 1)
# Display him in a view
<%= @user.id %>
In ASP.NET MVC it's much harder
// Controller User user = new User(1); ViewData["user"] = user; // View <% User user = (MyNamespace.User)ViewData["user"]; %> <%= user.Id %>
With this ViewData thing all benefits of static languages go away, and we waste time boxing/unboxing objects.
P.S. Don't tell me to use Model object, because this is also true for other variables like integer.
And another question:
I'm trying to implement a comfrtable access to data. Since I can't use LINQ to SQL as I use Postrgresql, I have to do it on my own. I'm tired of direct SQL queries, so I'm trying to implement something like this:
I have a drop down list that has the initials of about 12 of our sales guys.How can I make it so that when they select their initials from the list, the next drop down list only shows their customers.In my database there is a column for customer name and salesman.
How can I have 2 Cascading Drop Down Lists for the same Drop Down List?here is my problemi have 3 drop down lists read from database1- Schools List 2- Classes List3- Teachers ListEvery School will have more than 1 Class and more than 1 TeacherWhat I want is when user select a School from Schools Drop Down List then BOTH (Classes and Teachers) should be refreshed based on the School Drop Down List
I have drop down list box that I would like to show two columns, is this possible? Or can it be done with a list box?The query correctly retrieves all of the table data to be displayed, one colum is an abbreviation, the other a bit longer description.
I have a requirement in my application that, while saving the application, need to get all the value from drop down list and pass it to the view model. But application should not allow the user to select more than one item from drop down list manually, ie, only one value at a time. My view model is like ...
public class ListManagement { public IEnumerable<selectListItem> InactiveProduct { get; set; } public string[] InactiveProductSelected { get; set; } public IEnumerable<selectListItem> ActiveProduct { get; set; } }
I have two drop down list on a page. The first one list projects and the second list users. The userlist is populated with an object datasourse that pulls a list of users for the selected Project.Whenever the Project list selection changes the second ddl Userlist always reverts to the first person in the list instead the person that was selected before a new Project was chosen.
I am trying to create an MVC List View that can be filtered by the value selected from a drop down list.
Selecting a value should repost the page ... Since there is no concept of view state data I am having some issues with this ... I can get the repost to take place but my drop down resets and I am not able to get the value that was selected.
ASSET CONTROLLER:
[Code]....
[Code]....
I have tried many of the posts that refer to setting up drop down lists but can't set them up in the content because this is a List View.
I have a class with all different kinds of data members, including a list of strings. When I bind the data to a GridView, I want to be able to separate out the list of strings into different columns in the GridView. These strings are more like flags, there is a max of 3 flags. The list could be empty, if no flags apply, or it could contain only one or two flags. How can I separate out these flags into different GridView columns? Do I need to do it in the OnRowDataBound event?
Current, my aspx code looks something like this. I want to be able to change the ImageUrl of the Image controls based on if the flag is raised or not.
I had ddl which in selected changed it execute some code but when i tried to do that it wasn't worked well WHEN i checked the reason i found that ddl in selected value =0 also i made all well and this is my code
protected void DDlProductFamily_SelectedIndexChanged(object sender, EventArgs e) { if (DDlProductFamily.DataValueField.Contains("ProductCategory_Id")) using (SqlConnection Con = Connection.GetConnection()) { SqlCommand Com = new SqlCommand("GetListViewByProductCategory", Con); Com.CommandType = CommandType.StoredProcedure; Com.Parameters.Add(Parameter.NewInt("@ProductCategory_Id", DDlProductFamily.SelectedValue.ToString())); SqlDataAdapter DA = new SqlDataAdapter(Com); DA.Fill(dt); DataList1.DataSource = dt; DataList1.DataBind(); } }
When the user navigates to a new page, this ddl's selected index is determined by a cookie, but if the ddl doesn't contain that cookie's value, then I'd like it to be set the 0. What method would I use for the ddl? Is a loop the best way, or is there a simply if statement I can perform?
This is what I've attempted, but it doesn't return a bool.
if ( !ddlCustomerNumber.Items.FindByText( GetCustomerNumberCookie().ToString() ) ) ddlCustomerNumber.SelectedIndex = 0;
I want to be able to have '0' (zero) for CampaignId for "--Select Campaign--" selection. Is this possible to specify 0(zero) for "--Select Campaign-- option instead of ""?
I have a page that has two drop down lists on it and a button. All controls sit in an update panel. The first drop down list (ddl1) contains a lot of values which caused a huge viewstate so I disabled viewstate on it. In the page oninit event I populate the drop down list every time the page is posted back. This all seems to work fine, it shows all the values and I can access the selected value in my event handler.
ddl1 has the autopostback attribute set to true so when its value changes the second drop down list (ddl2) is populated with some values that depend on the selection in ddl1. This also works fine, the values in ddl2 change when I select a value in ddl1.
ddl2 does not have viewstate disabled. The button that sits under my two drop down lists is disabled by default and becomes enabled when the value of ddl2 is changed to anything except string.empty. This is where I run into problems. ddl2 does an autopostback too but it seems to lose the selected index/value. When I'm in my code to check whether to enable or disable the button the selected index is always 0 and the selected value is string.Empty.
If I enable viewstate on ddl1 this all works fine. Could anyone point me to what I'm doing wrong?