MVC :: Form With Data Of Different Models And With Dropdown List

Feb 16, 2011

I am working on the following form: This is a smooth popup, I make it appear through ajax using:

$.get('/UsuariosEmpresa/Create/', function (data) {
$("#AltaUsuarioProtectiveLayer").fadeIn("fast");
$("#PnlAlta").html(data);
});

What is great. And the View for create has the following code:

[Code]....

By now I have this two Save Buttons, Save and btnGrabar, just to test. When I use Save it is sending all the information, but not the values for the "Grupo" and "Empresa" dropdownlists. I am trying to use an Editor Template, but I don't know if is the best way, or is better to make in another way: 2 pages, one for create and one for edit. I have the following ViewModel that I try to use here:

[Code]....

And the dropdown list are in the editor template in this way, they are relation dropdownlist so depending on the Grupo=Group will show the corresponding Empresas=Companies:

[Code]....

And there is the problem I believe. The db diagram for this part is the following: The question are:

a- What is the best way to do this?
b- Is ok to use a template?
c- How should I send the information to save correctly the id_Empresa value?
d- Is ok to use the ViewModels or is better to send all the values as $.post parameters?
e- Is ok the way I cascade the dropdownlist?

View 3 Replies


Similar Messages:

Forms Data Controls :: 2 Dropdown List / "Displaying A Dropdown List Of Categories With A --None -- Option?

Oct 10, 2010

I am stuck at this point "Displaying a dropdown list of Categories with a --None -- Option. I want the gridview control to display 2 dropdown list one in read-only mode and the other in edit mode. When a record is in read-only mode, the dropdownlist's enabled property will be set to false."When it's on a read-only mode, it doesn't display the selected Category. it shows but the "No Category". When i click on edit to edit or change category, it doesn't display the selected category.

The example is given below( I am reading the book Sams Teach yourself ASP.NET 2.0 by Scott Mitchell. page 628)

<asp:Label ID="UserIdValue" runat="server" Visible="False"></asp:Label>
<asp:SqlDataSource ID="picturesDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [Pictures] WHERE ([UserId] = @UserId) ORDER BY [UploadedOn] DESC"
DeleteCommand="DELETE FROM [Pictures] WHERE [PictureID] = @PictureID"
InsertCommand="INSERT INTO [Pictures] ([UserId], [CategoryID], [Title], [Description], [UploadedOn]) VALUES (@UserId, @CategoryID, @Title, @Description, @UploadedOn)"
UpdateCommand="UPDATE [Pictures] SET [UserId] = @UserId, [CategoryID] = @CategoryID, [Title] = @Title, [Description] = @Description, [UploadedOn] = @UploadedOn WHERE [PictureID] = @PictureID">
<DeleteParameters>
<asp:Parameter Name="PictureID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="UserId" />
<asp:Parameter Name="CategoryID" Type="Int32" />
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="UploadedOn" Type="DateTime" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="UserIdValue" Name="UserId" PropertyName="Text"/>
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="UserId"/>
<asp:Parameter Name="CategoryID" Type="Int32" />
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="UploadedOn" Type="DateTime" />
<asp:Parameter Name="PictureID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<asp:SqlDataSource ID="categoriesDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [CategoryID], [Name] FROM [Categories] WHERE ([UserId] = @UserId)">
<SelectParameters>
<asp:ControlParameter ControlID="UserIdValue" Name="UserId" PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<asp:SqlDataSource ID="maxPictureIDDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT MAX(PictureID)
FROM Pictures
WHERE UserId = @UserId">
<SelectParameters>
<asp:ControlParameter ControlID="UserIdValue" Name="UserId"
PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<asp:Label ID="cannotUploadImageMessage" runat="server"
Text="The photo could not be added to your album either because you did not specify a file to upload or the file specified was not a JPEG image with the file extension .JPG"></asp:Label>
<br />
<asp:DetailsView ID="dvPictureInsert" runat="server"
DataSourceID="PicturesDataSource" Height="50px" Width="125px"
AutoGenerateRows="False" CellPadding="4" DataKeyNames="PictureID"
DefaultMode="Insert" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
<EditRowStyle BackColor="#2461BF" />
<FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
<Fields>
<asp:TemplateField HeaderText="Picture">
<InsertItemTemplate>
<asp:FileUpload ID="imageUpload" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="imageUpload" Display="Dynamic"
ErrorMessage="There was no file selected" ValidationGroup="PictureAdd"></asp:RequiredFieldValidator>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Category" SortExpression="CategoryID">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("CategoryID") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="pictureCategory" DataSourceID="categoriesDataSource"
runat="server" DataTextField="Name" DataValueField="CategoryID"
SelectedValue='<%# Bind("CategoryID") %>'
Visible='<%# Bind("CategoryID") %>' AppendDataBoundItems="True">
<asp:ListItem Selected="True" Value="">-- Select Category --</asp:ListItem>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("CategoryID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title" SortExpression="Title">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Title") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Title") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" Display="Dynamic"
ErrorMessage="you must provide a name for the title"
ValidationGroup="PictureAdd"></asp:RequiredFieldValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description" SortExpression="Description">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Description") %>'

View 2 Replies

C# - How To Disable Dropdown List Value In The Current Form That Was Selected In The Previous Page

Aug 27, 2010

I am having 2 web formsand will have a drop down list on those web forms. If i select a value from drop down and click on ok i will get tranfer to next page. In that page i will have a drop down with the same values in the previous form . What i need is i would like to disable the selected value in the previos form and would like to display the remaining normal

View 2 Replies

Web Forms :: How To Disable Dropdown List Value In The Current Form That Was Selected In The Previous Page

Aug 27, 2010

I am having 2 web formsand will have a drop down list on those web forms. If i select a value from drop down and click on ok i will get tranfer to next page. In that page i will have a drop down with the same values in the previous form . What i need is i would like to disable the selected value in the previos form and would like to display the remaining normal.

View 3 Replies

MVC :: Getting 2 Models From A Form?

Mar 17, 2011

I am doing a registration form where the user enters his account information, and some other misc. information.

The misc. information are stored in another table and hence has its own model.

How do I have the model binder creates 2 model, or should I have one combined model?

View 1 Replies

MVC :: List Of Models Inside Another Model?

Dec 30, 2010

I've a product model that contains a list of description models. Every description model contains some string values because every product can have a description for every language. Here it is a semplified version of my models:

[Code]....

So my view to insert a new product is like this:

[Code]....

And my PartialProductDescription view is like this:

[Code]....

Now, the views are perfect. With some Jquery UI I have a form with all the product properties and a tab panel with the language descriptions.

Unfortunatelly my POST action with the firm public ActionResult ProductNew(ProductModel model) has all the model property InternationalDescriptions that contain 2 empty models. So if I write something in the form in the first description textarea, model.InternationalDescrtiptions[0].Description is always empty.

So, how I can tell to MVC to take description textarea values and put them in the model?

View 6 Replies

Forms Data Controls :: Databound Dropdown List / Shows First Value In List Rather Than Current Value?

Jan 17, 2011

I have a databound dropdownlist and have a problem with the default value it selects.When I attempt to edit a record the dropdownlist shows the first value in the list rather than the current value. I want the dropdown list to display the current value.

I'm sure this is very simple but I'm very new to ASP.NET.

I'm using .NET version 4.

View 4 Replies

MVC :: Making Base Models With View Models

Nov 3, 2010

i have a base controller that looks like this:

[Code]....

and a contact model that inherits from the base model.

the master page inherits form the base model,

nad the contact page inherits from the contact nodel,

but then i get an error while loading the contact page that it expects the contact model but gets the base model?

View 9 Replies

Web Forms :: Dropdown List To Dropdown List GUID?

Nov 3, 2010

I have 2 drop down lists.I have a very simple dropdown list #1 that diplays a title and holds an id value which is a GUID.I know it is getting this value and sending this value as I tested sending it to a label.I have the dropdown list #1 to autopostback to dropdown list #2 that "Is supposed to get" another title and value based on the GUID value of the first dropdown list. for some reason it wont return anything. I have done 100's of these but never based off a guid value.I assume the value needs to be converted to guid before selecting it in the second dropdown list.How can I do this? or is there something I am missing?

View 9 Replies

Web Forms :: When Selecting An Item From One Dropdown List It Populates The 2nd Dropdown On Aspx Page?

Sep 8, 2010

Does anyone know how to do this so when I select something the 1st dropdown and the 2nd one becomes visible and populates list from a Select statement. I really need help on how to do in an aspx and not on the code behind page.

View 12 Replies

Web Forms :: DropDown List Not Retaining The Values(the DropDown Inside Gridview Control)?

Jun 12, 2010

I Have the gridview control with 2 dropdown list and 2 text boxes,When the textbox chnaged event happen 1 row will create and the dropdown back to initial values( its not retaining the selected values),I am binding the control after text changed method,Is there any properties needs to be set or any other way we can retain the values in postbacks?

View 4 Replies

JQGrid Inline Editing - Filter Subcategory Dropdown List Based On Another Category Dropdown

Jul 9, 2010

I have a category and a subcategory column in a Jqgrid. I have enabled inline editing, both category and subcategory are dropdownlists columns (edittype:'select'). I need to filter the subcategory list based on the selected category. I wonder how can I acheive this functionlity? I tried the below event but its not working for me

afterEditCell: function(rowid, celname, value, iRow, iCol) {
//to do here
}

the above event doesn't get fired. my all column are editable

View 1 Replies

Web Forms :: How To Use DropDown List To Group By Data

Mar 15, 2010

[Code]....

here i include my coding...

when i compile it..it show the data wit the noted data..

my question is...i want use dropdown menu to select the "category"...

how to use it? lets say i choose "Furniture" the output should be the data under Furniture category

View 5 Replies

Web Forms :: Dropdown List Is Not Retrieving Data?

Aug 9, 2010

I have a photo website with a login page. (It is an exercise out of a book: Scott Mitchell's "ASP.Net in 24 hours".) After a user logs in he can go to another page and manage photo categories. That page works. I have two users that have photo categories setup in the database.

There is also a page where a user can add photo images. This is the page that is giving me problems. It has a name and description field. (The functionality for uploading a photo is next in the book. It is not on the page yet.) The page also has a dropdown list that is supposed to be populated by the category names of the logged in user. This is the control that is giving me problems. It is not being populated by the logged in user's Category names.

The two database tables used are pretty simple:

[code]....

There are two SQLDataSources on the page:

One is for inserting new photos. The other retrieves the Categories of the current user. The page has a DetailsView with the Photo's Title and Description. There is also a dropdown list with the Category names. It is aa InsertItem Template in DetailsView.

When the page opens, the current UserID is retrieved and put into a Hidden Field. It is then used to retrieve the Category Names by the second SQLDataSource. I have gone through the book's steps a few times now. The dropdown list is not being populated. I am not getting any errors.

How can I track down why the dropdown list is not being populated?

Both of my users have Category values set up in the database. So, the dropdown list has values that should be appearing.

Here is the source code:

[Code]....

View 3 Replies

How To Add Data From Database In Dropdown List Manually

Sep 5, 2010

How to add data from database in drop down list manually?

I have added it as:

In the database table name tbldate there is field day and I have to add all these dates manually as:

dropdownlist1 is id for drop downlist and dr is object of data reader which get the value after select command from the above said table.

dropdownlist1.datasource=dr["day"].tostring();
dropdownlist1.databind();

But it shows only value 17 in dropdownlist why?

View 10 Replies

C# - Accessing Data From Sql In Two Dropdown List At Same Time

Mar 17, 2011

i have two drop down list in web form..for both of them i've used following code to bind with sql..but whenever i'm trying to bind second drop down list with same method..it's giving error..
the code i've used:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlPropertyType.AppendDataBoundItems = true;
String strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
String strQuery = "select ID, PropertyName from PropertyType";
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = strQuery;
cmd.Connection = con;
try
{
con.Open();
ddlPropertyType.DataSource = cmd.ExecuteReader();
ddlPropertyType.DataTextField = "PropertyName";
ddlPropertyType.DataValueField = "ID";
ddlPropertyType.DataBind();
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}
}
}

View 2 Replies

Web Forms :: Binding Data To A Dropdown List

Aug 4, 2010

one drop down list cointains all country list ,when we select thet particular country the other drop down list has to show all the states in that country ,this is what i am thinking to do ,can some one guide me how to do ,and give you give some reference links

View 3 Replies

Web Forms :: Can't Compare Data Of One Dropdown List With Another DDL

Apr 22, 2010

I have a web form where there are couple of DDL's; DDL1 and DDL2 respectively. I want the DDL2 to be populated based on the selection made in DDL1. From the DDL1, I just want to extract the first three digits of the value selected in DDL1 and use it in the WHERE clause of SQL query which is used to generate DDL2.

My prob is that I am not able to extract the first three digits out of DDL1 and use it in the WHERE clause of DDL2. I have pasted all my code below:

Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ddl1Value As String = DropDownList1.SelectedValue
ddl1Value = (ddl1Value.Substring(0, 3))
SqlDataSource3.SelectParameters(0).DefaultValue = ddl1Value
SqlDataSource3.DataBind()
End Sub

Code for DDL2:

<asp:DropDownList ID="DropDownList2" runat="server" CssClass="style29"
DataSourceID="SqlDataSource3" DataTextField="IXC_Vendor_Name"
AutoPostBack="True" AppendDataBoundItems="true"
DataValueField="IXC_Vendor_Name" Height="24px" Width="338px"
onselectedindexchanged="DropDownList10_SelectedIndexChanged">
<asp:ListItem Selected = "True" Text = " " Value = " " ></asp:ListItem>
</asp:DropDownList>.......

View 8 Replies

Data Controls :: How To Put Dropdown List In Gridview

Apr 27, 2016

I use gridview in page that use session to fill it below are code:

<asp:GridView runat="server" ID="gvOrders" EmptyDataText="No orderPlaced !" ShowFooter="true" CssClass="gridorder"
AutoGenerateColumns="false" DataKeyNames="Id">
<Columns>

[Code].....

quantity is in databound in gridview and it will show quantity of users order...

now I want in quantity column in gridview I can put Dropdownlist that will fill with numbers that if users want increase their order they can do it from gridview...

View 1 Replies

AJAX :: Display Cascading Dropdown List Based On Checkbox List Selected Value

Nov 10, 2010

How can i generate dropdown lists based on what has been selected in the checckbox list. Below is an example of what i need. if the user selects the options day, lotID and waferID, then 3 cascading dropdown lists should be displayed. And then a gridview displays data based on what has been chosen in the dropdown lists.

Day
LotID
SlotID
WaferID
VendorID
ToolID
LocationDetected
ProcessStep
Stage
Precipe
WaferStartMaterial
WaferStartVendor
WaferStartLot
WaferDiameterCOA
WaferMapTitle
BreakPoint
BreakpointSide
BreakpointMeasurement

View 3 Replies

Web Forms :: Clicking The Label Of A Dropdown List - Resets The Selected Value To The First Item In The List?

Feb 17, 2010

Clicking the label of a drop down list, re-sets the selected value to the first item in the list. This has a history of causing data entry problems when users accidently click on the label.

In the below example ddlContactType has a selected value as 'PRIMARY' and whenever i click on the lblContactType Text, the dropdown box Selected value is changing to "Select One" Text.

How to prevent this one. It should be on PRIMARY Only.

<p>
<tr> <td ><asp:Label ID="lblContactType" Font-Bold="true" Text="Contract Type: *" ForeColor= "red" runat="server" AssociatedControlID="ddlContactType"></asp:Label> </td> <td > <asp:DropDownList runat="server" ID="ddlContactType" DataSourceID="SqlDataSource2" AppendDataBoundItems="true"
DataTextField="TYPE" DataValueField="ID" SelectedValue='<%# Bind("CONTACT_TYPE_ID") %>'>
<asp:ListItem Text="Select One" Value="0" Selected="True"></asp:ListItem>.......

View 4 Replies

Populating A Dropdown List Based On Value Selected In Previous List (mvc3)

Mar 18, 2011

I'm trying to progam a strongly typed "Create" view using MVC 3 and razor. I want the user to be able to select a customer from a dropdown list (I populated this from my database using ViewBag in the controller). When the user has selected a customer I want a separate dropdown list to generate a list of dogs belonging to that customer related by the customerID in the database. The create button on the form will then take both of these values along with the the other fields and save it to the database.

View 1 Replies

Web Forms :: How To Accomulate Large Data At Dropdown List

May 3, 2010

I have a drop down list . In that list i have to show more then 3000 value comes form SQL Server database

Becasuse of huge amount of data the drop-down list preforms slowly.... is there any way so that the dropdownlist performs faster.

View 3 Replies

Forms Data Controls :: Use Dropdown List With Objectdatasource

Aug 13, 2010

I will try to keep the question short:

1. I am new to ASP and I can not get this to work:

2. I am Using a <asp:DropDownList in a <InsertItemTemplate> in a <asp:ListView

3. The dropdownlist during insert does not get polulated (it is empty) while the same construction and same datasource works in the edittemplate: <asp:DropDownList in a <EditTemplate> in a <asp:ListView

4. I noticed that filling the dropdownlist with a <asp:ListItem works; the insert list is populated. (not usable for me) In both cases I use the same datasource from the code behind like this : Edit:

<asp:DropDownList ID="DropDownStartday" runat="server" SelectedValue='<%# Bind("startday") %>'
DataSource="<%# GetDataSourceStartDay() %>" DataValueField="daynum" DataTextField="dayname"
Insert: (with or without Selectedvalue: NoJoy)
<asp:DropDownList ID="DropDownStartday" runat="server"
DataSource="<%# GetDataSourceStartDay() %>" DataValueField="daynum" DataTextField="dayname"

View 4 Replies

Web Forms :: Binding Data To Dropdown List From Database

Jul 7, 2010

I am not able bind data to the dropdownlist from database. following is code.

DataTable dtModule = BO.GetBizModel_DDL(ServiceID);
if (dtModule != null)
{
ddlBizModl.Items.Clear();
ddlBizModl.DataSource = dtModule;
ddlBizModl.DataTextField = "BIZ_MODL_NM";
ddlBizModl.DataValueField = "BIZ_MODL_ID";
ddlBizModl.DataBind();
}
dtModule.Dispose();

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved