C# - Creating A Dropdown With Data From Multiple Tables?
Apr 4, 2011
I want to create a dropdown of Vendors. I have a Vendors table in my DB, containing a VendorID and a CompanyID. The Company table contains a CompanyID and a Name.
I would like to have a dropdown with items that have the VendorID as the value and the Company Name as the text. But I don't know how to get the Name field from the related table to put in the dropdown, so I have the VendorID as the value and text. Here's what I have right now.
I'm passing in a model that contains this:
public IEnumerable<Vendor> Vendors { get; set; }
In my controller, I'm setting the value of Vendors like this:
MyDBEntities _entities = new MyDBEntities();
Vendors = _entities.Vendors;
Here is my dropdown list on the page:
<%= Html.DropDownListFor(m => m.VendorId, new SelectList(Model.Vendors, "VendorID", "VendorID"), "- Select a Vendor -")%>
I thought I could create a custom function - GetVendorsForDropdown - that would return only the data I needed, and changing my model to contain IEnumerable<Something>. But I don't know what the return type should be.
View 2 Replies
Similar Messages:
Jan 29, 2010
I have a dataset with 3 tables that are inner joined. Thsi dataset is connected to an object datasource which is connected to a gridview. So at runtime it displays data from the database. The problem is when I click on a save button to add information to the database it throughs me an error saying Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints. But if i have two tables in my dataset it works 100%. But the problem i need that 3 tables in order to pull the required information. And if i populate the gridview using code to select the information from the database and insert information it also works 100%.
View 3 Replies
Jul 22, 2013
I created 3 product table . A,B and c.
I show product of table in different gridview.
Now I am using one search box. but how to search product name with image in one query all of three table....
Simple how to search product from multiple table and show result...
View 1 Replies
May 7, 2015
I have storedprocedure which returns four or more dataset!
example here
How load and display all data in Default.aspx....
dataset 1
............................................
dataset 2
............................................
dataset 3
............................................
dataset 4
............................................
View 1 Replies
Jan 9, 2014
There are 2 DropDown one is "Category" other is "sub_category"
I want to show data in "sub_category" DropDown according to "category" Dropdown selected value.
But when "Category=C1" data should bind in DropDown from Database Table1 and when "Category=C2" or "Category=C3" data should bind in DropDown from Database Table2.
How to achieve this.
View 1 Replies
Mar 18, 2011
i am really confuse about the html dropdown helper. i cant reli find one info which describe clearly about every overload and how to use them.currently i gone through a problem which i spent one day and still cant resolve it, really hope can get the help here since i need to make tis work for my final year project..i have a food table, and a foodtype table. each food will have a type, so the FoodTypeID is the FK for Food table.i want to have a create and edit page for Food. on the page, i want to provide a dropdownlist for user to select the food typethe FoodTypeName column that store the food type description is at the FoodType table, so i need to get the value of FoodTypeID based on user selection on the dropdown.I had tried for hourssss to do this bt i either get a compilation or cant save the new foodType selected in db
[Code]....
in fact, i not reli understand wat should be put inside the model => xxx and the dropdown helper overload, i am writing this based on the mvc tutorial
View 12 Replies
Jan 4, 2011
I have an C# ASP application I am writing that needs to have the capability to import a generated excel or a comma delineated sheet each day. A clerk will have this job each morning so it doesn't need to be automated. My problem in trying to understand the solution to this is that the 1 sheet contains loan information, including customer information all in the same sheet. I would like to send certain columns to update information in the loan table and send other information to update the customer table. I need it to create relationships when new loans appear in the spreadsheet.
View 1 Replies
Oct 25, 2010
Example: we have different articles in a database like cars, jewelery, boats. The data related to these articles is different in the tables. I have to show that data in a textboxes and let the user change those data and update. I can do the update and reading the data from database. But the problems is for each item the no.of columns and rows will differ.
My task is I need to get the data according to the use selection in the table with textboxes. I dont know which container (gridview, formview or etc) will suites for my requirement. send me any sample code or any tutorial related to this.
Note: showing the data in a table should be a constraint. Because I should show data row wise (each row contains 3 textboxes and 3 labels (DB table column names))
View 6 Replies
Aug 14, 2010
creating a dropdown similar to the time dropdown in outlook, located in the recurring event. The dropdown shows intervals of 30 minutes based on a 12 hour time format and allows the ability to put text in it.
View 1 Replies
Jan 17, 2011
I am trying to insert data into a table using data from 2 other tables.
I need to use:
Project.ProjectID and Action.ActionID to be inserted into a table I have called
ActionDetails, WHERE the Project.ProjectID = 1
i've googled everywhere with no success :(
View 2 Replies
Jan 22, 2010
I am using mysql as my database.From one of my web pages I want to insert data to 4 tables.All the data should be inserted to these different tables on a single button click from the web page.How can I achieve this?Which is most reliable way to insert data to multiple tables on a single click event?
Will the sql operation with 4 'insert' statements separated by semicolon work for me?
View 2 Replies
Sep 17, 2010
I have excel file with columns EmpName,Date1,Date2,...Date7 .I want to insert EmpName into Employee table after inserting i will get EmpNo(Identity column) with that i need to insert Date1,Date2...Date7 into TimeSheet table.
My Excel structure is like this
EmpName 8/1/2010 8/2/2010 8/3/2010 8/4/2010 8/5/2010 8/6/2010 8/7/2010
Naresh 17:00-2:00 17:00-2:00 14:00-12:00 7:00-12:00 7:00-12:00 .. Off
Similarly 500 employees data
I want to insert name i.e into Emp table after inserting i will get EMpNo i.e identity column with that i should insert Date1(8/1/2010) i.e excel header to date7 into Timesheet table Date column and corresponding time into TimeIn and TimeOut.I will split the time.I just want write Stored procedure for this task.
My database tables are like this
Emp-EmpNo,EmpName,CompaignId
Timesheet-TimeID,EMpNo,Date,TimeIn,TimeOut,TotalHours
Date in Timesheet should be like this
TimeId EmpNo Date TimeIn TimeOut T otalHours
1 100 8/1/2010 17:00 2:00 9hrs
2 100 8/2/2010 17:00 2:00 9 hrs
7
I just want this logic on how to insert Date1 to date 7 as 7 rows into Timesheet table and EMpName into EMployee table.while accesing each row i need to insert Date 1 to date7 as 7 rows into Timesheet table.
View 2 Replies
Nov 30, 2010
I am having a hard time solving the following with an MVC view. My goal is to display data from multiple tables in a single MVC view. The bulk of the data comes from a table called Retailers. I also have another table called RetailerCategories which stores the retailerid from the Retailers table and also a categoryid linking to a Category table. Note that there are multiple records for each retailerid in the RetailerCategories table.
In the view I want to show a list of retailers and with each retailer I want to show the list of categories applicable to them. What would be the best way to accomplish this?
View 2 Replies
Aug 17, 2010
I have hard time trying to find the solution to retrieve data from multiple tables in one database.
table Kategorije has fields: idKategorija, naziv, opis table Clanak has fields: idClanak, idKategorija, naslov, autor,...
Kategorije.idKategorijais joined with Clanak.idKategorija, but that isn't the solution because I want my web site to show the Kategorije.naziv instead of Kategorije.idKategorija. This is the code I'm currently using to get idKategorije shown on my web site:
[Code]....
[Code]....
View 3 Replies
Feb 11, 2011
So I have two tables in my database, Contacts and Addresses:
Contacts : ContactID | AddressID | FirstName | LastName
Addresses: AddressID | Address1 | Address2 | City | State | Zipcode
I have a page where you can add a contact. It contains all the information for a contact and an address for a contact. Here's my code for when you submit the form:
[code]...
Now my main concern is that the address is added successfully, but then an error occurs when I try to save the contact, leaving the address in the database with no contact.
What's the best practice here for rolling back any changes if an error occurs?
View 4 Replies
Dec 5, 2010
I'm fairly new to all this, but have slowly been teaching myself C# and ASP.net MVC over the past year or so...I really tried to search for this, but haven't been able to find anything - it may be I'm using the wrong terminology!I'm using ASP.NET MVC2 with EF4 connected to a SQL Express db. Situation: Without getting into too much specifics, I have one table called 'Plan.' Under 'Plan' are several different categories that are related to a single Plan item [say Category A, Category B, Category C and Category D]. Each 'Category X' table has a beginDate, endDate and other details specific to that category.
I'd like to be able to create a summary page that combines all items from Category A, Category B, Category C, and Category D and sorts by beginDate - but only need a few of the columns [eg - begin/end date, name, id].
View 1 Replies
May 6, 2010
I have to write data to multiple (two) tables.
tbl1 has a column "ORDERID" with auto increment. I have to get this "ORDERID" whenever I write to tbl1 (Insert new record)
tbl2 has a coumn "ORDERID" as foreign key, I have to write "ORDERID" in tbl2 received from the tbl1.
How to do it using SQL ( I am not using StoredProcedure)
View 5 Replies
Aug 20, 2010
i would like to find out how to go about displaying data from multiple database tables on the same page. What i mean is it would look like the feeds on the facebook home page where you can see the information like newply uploaded photo or a new post.
I have two tables, and i want to display any newly created row on my home page from either table in the same control. Currently, i have two gridviews, but i want the data from both tables be displayed together.
View 4 Replies
Dec 27, 2012
i have a details table which include detailid, custname, address, classification , pincode, telephone, remarks and classification table contain classification id & classification.i want to insert detailid & corresponding classificationid to a new table detail_classification. How to write stored procedure for that?
View 1 Replies
Jul 17, 2015
In article Load on demand data in GridView you clearly described. but it's not enough when we comes to conditions.
Is it possible to load data on query method?I want to add some field from other table so how to use inner join in this...
Like I'm having a table with userid and want to get user full name from users table where userId = users.userId
View 1 Replies
Jan 22, 2010
I have a listview that shows the user the details of the members who have sent friendship request. The table from which the data come has two fields namely, sender_id[id of the one who sends friendship request] and receiver_id[id of the one to whom the request is sent].
There will be two columns in the listview. The first would show the pic and the name of the user. The problem is that how am I going to show the pic and the name if the table from where the data come does not contain these info. I know that the sender_id can be used to fetch the pic and name of the sender, but how should it be done?
Earlier I would do something like <%#Eval("fieldName")%>. But in the above described scenario the field is not present in the current table but the other one.
View 5 Replies
May 7, 2015
I have to display records from two tables where foreign key table contains many values for a primary key column how to get the data using linq query???
View 1 Replies
Mar 16, 2010
I am writting a directory website that advertises fitness classes. These classes are listed by Class Type, and Geographical Area. Each Class Type can satisfy one or more of four Fitness Goals such as Loose Weight etc...
I have a table for Classes (classid, classname, classdesc, classtypeid, geoareaid) I have a table for geographic areas (geoareaid, geoarea) And I have a table for ClassTypes (classtypeid, classtypename, classtypedesc)
Which obviously links geographic area via the classes.geoareaid as a forgien key and classtypes by classes.classtypeid as a forgien key.
I can list all classes by type and also by geo area no problem, the problem arrises when I then also want to filter by goal.
The Goals Table (goalid, goal, goaldesc) is linked to the classtypes table via another table classtypes_goals (classtypeid, goalid) as each classtype can satisfy any of the 4 goals.
I am using a DataSet to fetch the data from a Stored Procedure in the SQL Database but because the classtypes can be linked to multiple goals I am getting duplication in my list depending on how many goals a classtype satisfies.
All I need in my data list is class name, class type and area I don't even need to display the goal I just want a drop down above the table that will filter the list and show only classes of classtype that satisfy the goal chosen.
View 18 Replies
Nov 29, 2010
I have a asp:DetailsView control with the first column are the field headers and the second column is the record details for a given user.
The DetailsView is bound from 4 tables, I need to be able to edit/amend any field. Is there another way I can achieve this from the DetailsView? Would I need to create templates for each table entry then Update SET on each template, would that do it?
View 8 Replies
Mar 3, 2011
I have 2 tables
One:Table Name Rider With columns RiderID,LName,City
Two:Table Name Car With columns CarID,RiderID,Color
What I would like to be able to do is to allow the users to do an UPDATE on both tables.
Like if you crreated a SQLDataSource using just one table as it's source. You can use that SQLDataSource for a gridview.
Then in the gridview you can display all the data from the table but you can also EDIT all the data in the table through the gridview.
But if I create a SQLDataSource using 2 table joining them together with an INNER JOIN with a Primary Key in one table and a Foriegn Key in the other table. I can still use this SQLDataSource with a GridView to display the data but I can't EDIT the data through the gridview for the 2 tables.
Is there anyway to do this using a SQLDataSource and GridView?
OR is there another way to accomplish this?
View 3 Replies