.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Cannot get ForeignKey to populate Dropdown

Posted By:      Posted Date: October 14, 2010    Points: 0   Category :ASP.Net

I am using a DynamicData - Entity project.  I have added a DynamicDataManager with AutoForeignKeys = true and also added a EntityDataSource with an include to the associated table.

<asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true" >


<asp:DataControlReference ControlID="gvContact" />



<asp:EntityDataSource ID="EDS1" runat="server"



Include="Ref_Values, Ref_States">



The contacts table has many to one relationship with the Ref_Values and Ref_States table were it shoud retrieve a "text" value for the job title and state.

When the page is ran the gridview returns the integer value that is in the DonorContacts table not the foreign key value.

I have ensured that the relationship exist and that all tables have a primary key.  Also if I set the scaffold to true in the global.asax file and view the DonorContacts table the columns in question display the expected data, not the int.

I can get the correct value by using

View Complete Post

More Related Resource Links

populate dropdown based on attribute criteria

Trying to load a dropdown list with the 'name' attribute from the category node...must be missing something: The xml: <Settings>  <department name="Accounting">    <category name="Bank Information">    <category name="Form Information"></Settings>    The code I'm attempting: XmlDocument settingsdoc = new XmlDocument();                settingsdoc.Load(Server.MapPath("/XML/Settings.xml"));                XmlNodeList nodeList = doc.SelectNodes("Settings/department[name='Accounting']");                 foreach (XmlNode node in nodeList)                    CategoryDDL.Items.Add(new ListItem(node.SelectSingleNode("//department/category[name]").InnerText)); CategoryDDL.DataBind();   Any idea what looks wrong? Thanks!

dropdown list wont populate values from database


Hello everyone i need help. Ive been having this problem for almost  3 days now. dropdown list won't populate from database

Below is the code i am using:

<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="PhotoAlbum.aspx.vb" Inherits="PhotoAlbum" %>

<asp:SqlDataSource ID="categoriesDataSource" runat="server"  
<%$ ConnectionStrings:ConnectionString %>"  
    SelectCommand="SELECT [CategoryID], [Name] FROM [Categories] WHERE ([UserId] = @UserId) ORDER BY [Name]"> 
<asp:QueryStringParameter Name="UserId" QueryStringField="ID"/> 

Populate in dropdown list control


Hello need some help on this one.  I am using ASP.NET with C# and Oracle database. I am trying to return some values from my select statement to fill my dropdown list control. I am designing this in a 3 tier architecture.  Here is my codes.  I am getting an error which states "Object reference not set to an instance of an object." I am returning the field name "NAME" to be filled in my dropdown control.  What I am doing wrong?


List.cs file code

public static string _GetClientList()


string clients = string.Empty;int SessUserID =

populate day dropdown on month change

<script type="text/javascript" language="javascript">
function testDate(value)

// var sel = document.forms(0).DDAY;
var sel =document.getElementById('DDAY');

sel.options.length = 0;

var NoOfDays = DaysInMonth(value);

for(var i=1;i<=NoOfDays;i++)
//create new option
var option = new Option(i, "Value" + i);
sel.options(i) = option;


<select onchange="testDate(this.value)" id="MMONTH" style="display: none;
z-index: 101; left: 0px; width: 80px; position: absolute; top: 2px" runat="server">
<option selected="selected" value="01">JAN</option>
<option value="02">FEB</option>
<option value="03">MAR</option>
<option value="04">APR</option>
<option value="05">MAY</option>
<option value="06">JUN</option>
<option value="07">JUL</option>
<option value="08">AUG</option>
<option value="09">SEP</option>
<option value="10">OCT</option&g

how to populate a dropdown box based on selectedvalue in another dropdown/combo box



I am new to MVC.  Can anyone show me how to populate a dropdown list box based on selected value in another

dropdown list box?  Say, for example, the first dropdown is a list of car manufactures.  When a user selected a manufacture from that dropdown list, the second dropdown would list would automatically gets populated with all the car models for that manufacture. 

Any help is greatly appreciated.



populate dropdown with code



i have 2 dropdown fields the first drop dropdown ownly holds 2 items : "technical questions","broken stuff".

i have made 2 data connection with the right lists.

the second drop down i want to populate, depending on the selected value.


i was thinking, i have already the data connections when i go to the code on the change event.

i can work with this data connection and populate the dropdown.

but i'm dooing something worng can anybody give some suggestions?



Dropdown list in ASP.NET - How to get value selected

am sure this must be very simple, but unforunately I can't figure it out.
I have the following code which populates the dropdown lists from the database. This works fine. Now, when the user selects a particular employee name from the list, I want to get the Employee Id of the selected employee. i.e. I need to get the "Eid" value. I can do this if the EId is loaded in the dropdown list, but in this case only the employee name is displayed. Please let me know howI can get the Eid value even though it is not loaded in the dropdown list.
I would really appreciate your help

Editable Gridview with Textbox, CheckBox, Radio Button and DropDown List

This is an example of an editable gridview containing different ASP.NET controls. When user wants to edit values in gridview, she/he can use these controls to edit existing values in Gridview Edit Mode.

Using the Code

Binding an array to dropdown list


I have the following string which is a list of urls. How do I get this to work so the url shows for the selection and also is the value?      


allLinks = newAllLinks
        Me.DropDownList1.DataTextField = "Link"
        Me.DropDownList1.DataValueField = "LinkURL"
        Me.DropDownList1.Items.Insert(0, New ListItem(" - Select - ", 0))
        Me.DropDownList1.DataSource = allLinks


 ArgumentNullException: Value cannot be null.
Parameter name: container]
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +121
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName, String format) +8

Gridview with a dropdown list for editing


Hello. I am working through Scott Mitchell's ASP.Net in 24 hours book. I am finishing the photo album project.

I have a GridView that retrieves a list of uploaded photo rows for the logged-in user.
The GridView is for editing and deleting rows.

The photo Category field in the Gridview is a dropdown list. The text entry field was deleted after converting this field to a Template.

Like the uploaded photos, these Categories are user-specific. They are created in another web page.

Users also have the option to select "none" for the category when they upload an image.

For the GridView:  The Category ID field's ItemTemplate and EditItemTemplate both have a " - None - " choice added to them.

I am getting this error:

'pictureReadOnlyCategories' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value


Note: The ID for the ItemTemplate for that dropdown list is the ID listed above in the error: "pictureReadOnlyCategories".


Am I missing some step in this process of changing a GridViews text field to a dropdown that can be used for editing? I went through the book's instructions three times.

Here is my code for the dropdown list and a screenshot of the Design

Dropdown Event (Template Field)



I have grid view control that includes a dropdown control in a template field.

I wish to execute some code when the value is changed in the dropdown list.  Can't figure out how to capture this event though?

Any suggestions?

Populating Dropdown List using FK


Hi Folks,

2 Questions. I am trying out Data Entities in VWD 2010 Express. I have a parent (Customers) and child (Orders) table. Customers table has FirstName, LastName and Email columns.

Q1. When I view/edit/insert an Order, it shows the customer's first name in dropdown list whereas I want the full name. How can this be done?

Q2. How can I change the default behavior of PK/FK relationship so that customer's Email is displayed instead of Name?

Any help will be much appreciated.


Using a trigger or anything else to populate two tables


Hi! I'm creating an application that's supposed to first add a record to table1, and then get the ID from that record to use when adding a record to table2, to be able to associate these two records with eachother.

The user gets to type in some values that goes to table1, and some values that goes to table2, but before the insert statement for table2 is executed i need the ID from the recently added record in table1. Some dude told me to use a trigger for the autopopulate purpose, but does that really work when i also need to save some values that's user input, and when those values doesn't get saved in table1?

Are there any other way to do this or can i send values to a trigger? I'm new to triggers and stored procedures, i don't have any particular knowledge of this, any help is appreciated!


Regards, Monsterbadboll

Is it possible to populate property choices from a database?


I'm creating my first server control, and have it working where I can set up an enum and the user can set a property's choices,  based off of that enum.  But I'd like it to pull records from a database and populate the list of choices for the property from a database.  This would allow me to add a new "Host System" to the database, and the other designers wouldn't have to get a new copy of the dll.



populate report viewer by code


Hi all

I have a button "Show Report" to show some data from table

what I should write under this button to populate the reports ?

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend