.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

How to populate drop down list inside fromview using code?

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :ASP.Net


I have formview to read US cities as following:

- I use label to read the values in <ItemTemplate>

- I use dropdown list to read values in <EditItemTemplate> and < InsertItemTemplate>

When the formview get loaded it’s read all values properly, but when I move to edit or insert mode the dropdown list give me this error: Object reference not set to an instance of an object

Could anyone help me with example of code (Note: I use the code to fill the dropdown list instead of SqlDataSource )

Thank you in advance,



View Complete Post

More Related Resource Links

Can I populate a the drop-down list of a report parameter by custom code


Hi there,

I have a custom assembly that returns an Arraylist and I am wondering if I can populate the drop-down list of a particular parameter by this list. To me, it seems that I can either have static values for such a drop-down list or that I can query the items from a dataset. However, I do not see how I can populate the list using custom code.

Best wishes



Rules on Drop Down List to populate another text field


I have a last name field in infopath 2007 web form with a drop down on sharepoint list. When they select a certain last name, I want it to populate the primary dept field on form. I set up a rule on the last name to set the primary dept field = to the primary dept field on datasource when the last name field is not blank. What I am getting is the primary dept value for the first record in the datasource. I am trying to understand what record I have. Do I need to do another query back to the datasource with the last name field to have the correct entries available to populate the dept field with? Please give me some clue. I am a programmer but not grasping the interplay between the datasource and the form and noit finding what I need in numerous google searches.



code SQL to populate gridview with multiple random list box selections, How to


I could use some help in coding a query.

I have a list box that allows for multiple selections (holding down the control key) the selection quantity is basically unlimited, but realistically should never be more than 50 to 100 items from the listing of about 3000 items.

I need to collect the list of selected items from the drop down list and retrieve each of their full records from the item master and populate a gridview.

Any help would be greatly appreciated.


Thanks again,



Populate Drop-Down list box from Active Directory Data Connection?


I recently created a data connection to my active directory, so that certain fields can be automatically populated given the user who is filling in the form.

However, I would like to have a drop-down box that is populated from Active Directory (i.e. the user of the form can select another AD member), the result of which will then populate other fields (with information such as Manager, Email Address, etc).

So, 2 questions:

  1. How do I get a drop-down list to populate with the members of AD?
  2. How do I get the result of this selection to populate other fields?
Cheers again - you guys are great!

SQL code to populate gridview with multiple random list box selections


I could use some help in coding a query.

I have a list box that allows for multiple selections (holding down the control key) the selection quantity is basically unlimited, but realistically should never be more than 50 to 100 items from the listing of about 3000 items.

I could really use some help building the SQL statement to select the choosen record data. I think I have the selection list worked out by populating an array but I am not clear on how to build the SQL query.

Any help would be greatly appreciated.


Thanks again

Drop down list inside Detail view


I am using a drop down list control inside Detail View but for some reason, its not picking up the selected value from database , secondly not being able to update the values either...Any idea?

<%@ Page Title="" Language="VB" MasterPageFile="~/__admin/_codefiles/Masterpages/admin.master"
    ValidateRequest="false" AutoEventWireup="false" CodeFile="ArticleTypeDetail.aspx.vb"
    Inherits="__admin_Admin_ArticleTypeDetail" %>

<%@ Register TagPrefix="tinymce" Namespace="Moxiecode.TinyMCE.Web" Assembly="Moxiecode.TinyMCE" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadPlaceHolder1" runat="Server">
    <style type="text/css">
            width: 300px;
            height: 50px;
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div style="padding-left: 22px;">
        <table cellpadding="0" cellspacing="0">
                    <div class="admin_blue_box">
                        Select the article type

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 ?

CLR Inside Out: Code Contracts


This article will share some of the best practices that the Base Class Libraries (BCL) team devised as they added the code contract libraries and started to take advantage of them in their own code.

Melitta Andersen

MSDN Magazine August 2009

Inside Microsoft patterns & practices: Building WPF and Silverlight Applications with a Single Code


This article discusses the Project Linker tool and other techniques to create applications that target both WPF and Silverlight from a single code base.

Erwin van der Valk

MSDN Magazine August 2009

CLR Inside Out: Best Practices For Managed And Native Code Interoperability


There are many factors to consider when building your app with both managed and native code. Find out how to employ interop and how to choose the interop that's right for you.

Jesse Kaplan

MSDN Magazine January 2009

CLR Inside Out: Marshaling between Managed and Unmanaged Code


Marshaling is an important part of .NET interop. It allows you to call into unmanaged code from managed code. This column will help you get started.

Yi Zhang and Xiaoying Guo

MSDN Magazine January 2008

Wicked Code: Drag and Drop with ASP.NET AJAX


Jeff Prosise shows how you can implement drag-and-drop functionality in your Web app with ASP.NET AJAX.

Jeff Prosise

MSDN Magazine January 2008

CLR Inside Out: Writing Reliable .NET Code


Here's a look at how code fails and techniques for writing more reliable and resilient managed code.

Alessandro Catorcini and Brian Grunkemeyer

MSDN Magazine December 2007

Way of adding items in Drop Down List or List Box using Javascript

The article Way of adding items in Drop Down List or List Box using Javascript was added by raja.s on Sunday, June 06, 2010.

Hi,script type="text/javascript"> function AddItem(Text,Value) { // Create an Option object var opt = document.createElement("option"); // Add an Option object to Drop Down/List Box document.getElementById("DropDownList"

Repeater issue, all code inside Repeater are not shown


I have a Repeater who should show some data from my ms.sql server. But all code inside the Repater is not shown on my .aspx page. What am i doing wrong. I have a similar Repeater on another page and there it works fine.


 <div class="AnsaettelseKontrakt Folders">
      	            <table cellpadding="0" cellspacing="0" width="750px" align="right">
                            <th class="BrugerHeader" style="width:300px;">Filnavn</th>
                            <th class="BrugerHeader" style="width:80px;">Størrelse</th>
                            <th class="BrugerHeader" style="width:150px;">Dato</th>
                            <th class="BrugerHeader" style="width:180px;" colspan="2">Brugere</th>
                            <th class="BrugerHeader" style="width:40px;">Værktøjer</th>
                        <asp:Repeater ID="RepeaterAns" runat="server" onitemcommand="Repeater1_ItemCommand" >
                                <tr class="Br

problem...i want a list item to populate all data in gridview!!!


i have a dropdownbox and a gridview

what I want is to have a list item which populates all data in a gridview.

I have tried using list item selected value=0 but to no avail.

what is the easiest way to achieve this?

How to use a drop down list to edit in the standard Edit.aspx with DD?


Hey All,

I'm brand new to Dynamic Data and to ASP.NET.  I've been able to fumble around and get the calendar extender up and running and a few other customization options implemented, but I can't seem to get this drop down list to work - even after reading tons of online info.  The good news is that my web page/application is VERY simple, so hopefully you guys can help me out.  I'm working in VB btw.

I have a list of road projects submitted to me by local governments.  One of the fields is SponsoringAgency, which has a limited number of possible entries (the names of member governments).  Thus, when they submit a new project, or edit an existing one, I want to limit the input into the field "SponsoringAgency." I'm trying to use a dropdownlist because I'm familiar with it from Access, but it may not be the best approach.  Imagine you just setup a brand new, standard DD website, how would you get this to work?

Methods tried and failed (probably because I don't understand them fully):

UIHint - The closest I can get with this is an error saying that since SponsoringAgency isn't a Foreign Key, I'm out of luck.

Creating a SponsoringAgency Table - In my data layer, I created a second table with a list of government names.  I then tried se

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