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

Post New Web Links

Drop Down List in FormView

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

hi all...

 i have create a registration form using FormView tool in asp.net..and i have a drop down list in form..

i use dropdown list in my cs page but i can't get the data into my dropdownlist in FormView Insert Template..(but no error display)

i use this code to get data to drop down list..


protected void Page_Load(object sender, EventArgs e)

            DropDownList ddlFreigh = (DropDownList)(FormView1.FindControl("ddlFreigh"));  //use this code get ddlFreigh in cs page from FormView

            if (!IsPostBack)
                // Create a database variable
                SqlConnection connection = new SqlConnection();
                // Set the connection string of the database

View Complete Post

More Related Resource Links

FormView Text Field Being Set by A Drop Down List


Hello, I have a FormView which is used to insert a record into a database.  Outside of this formview i have a drop down list, I want to grab the value from that drop down list and set one of the text fields within the formview to it's currently selected value.  I've tried the following code, but the dynamic categorytextbox line is what seems to not be working.

                    <asp:DropDownList ID="ddlCategory" runat="server" AutoPostBack="True" 
DataSourceID="SqlDataSourceCategory" DataTextField="CategoryName"
DataValueField="CategoryID" Width="200px">

                            <asp:TextBox ID="CategoryIDTextBox" runat="server" 
Text='<%# Bind("CategoryID") %>' Visible="False" />

        protected void FormView1_DataBound(object sender, EventArgs e)
dynamic varCategory = ddlCategory.SelectedValue;
dynamic categoryTextBox = FormView1.FindControl("CategoryIDText

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"

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

How to pupolate one Drop Down list values dynamically depending on the value of another Drop down fr


i have two dropdowns in my Custom form.

One drop down displays all the list titles present in the current site.

i want to update another drop down with the list of columns(Field Names not the items).

i am able to get list named in one drop down but i am not able to figure out how to dynamically populate the another drop down with list of columns

any ideas

Cascade Drop Down List Problem


I have 4 "cascade drop down linked" each other. The first one is "AccesoryFor", the second "TypeOfAccesory", the third "MarkOfAccesory" and the fourth "ModelOfAccesory".

The problem is that sometimes is possible in the web page I'm programming that a "Session Variable" could have a value that must be selected in one of that ddls. But not only that, the "ddl" or the entire "row" where the ddl is located ,must disappear. The problem is that, when the page does the rendering process, the others "cascade drop down" don't find its "control parents", so they stay disable and without data.

So, what I do in the Load Method:

 protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            Session["AccesoryFor"] = "cellphone";

 public void loadValuesToUI()
    if (Session["consultarRecursos_AccesorioDe"] != null)
            rowAccesoryFor.Visible = false;

As the row where the first DLL is located dissapears, and error occurs saying that "Control-Parents" are not found. There's no way to "Disable" or make dissapear the ddl in the web-service because

How can I Set default value for drop down list filled with Cascading

Hi AllI've this problem, how can I set the default value for drop down list filled with cascading. I can't catch the event that came after cascading to set the default value and I can't call any control in this function:  "AjaxControlToolkit.CascadingDropDownNameValue[]"   I've passed the Drop down list as a session and the default value in session   When I call the session of "Drop Down List" the session value Is NULL in this function:  "AjaxControlToolkit.CascadingDropDownNameValue[]"   Any help please. 

bind drop down list in content page from value from master page

Hi all, I have applied nested master page to some page. Now i want to bind drop downlist from value selected in dropdown list in master page of master applied to that page. the hierarchy of pages is  mypage.aspx -> main.aspx -> inner.master I want bind dropdown list in  mypage.aspx from  from value selected in dropdown list in  inner.master Please help me. 

how to in Insert database NULL if drop down list item is not selected ?

hi,   on my aspx I have the below DDL   <asp:DropDownList ID="ColorDDL" runat="server" DataSourceID="ColorObj"                                                 DataTextField="Size" DataValueField="BustId" Width="150px"                                                 AppendDataBoundItems="True">                                                    <asp:ListItem Value="-1">(Optional)</asp:ListItem>                             &n

How to get selected text of a drop down list in MVC?

I aggressively googled around, but could not find the information I am looking for.  I know how to populate a dropdownlist using my view model and Html.DropDownListFor helper method.Suppose the drop down list contains U.S. stateId and stateName key value pairs.  Suppose my ViewModel looks likepublic class MyViewModel{      public IList<State> States {get; set;}      public int SelectedStateId {get; set; }}public class State{     public int StateId {get; set; }     public string StateName {get; set; }}Now, in my controller's action method:[HttpPost]public ViewResult Index(MyViewModel  myViewModel){     // This following line seems to work fine, myViewModel automatically      // picks up the selected item of the drop down list.  How does this work?      // Is this the so-called model binding?      int selectedStateId = myViewModel.SelectedStateId;      // But, then, how do I get the selected state name?     string stateName = ??????????????     ... ... }Do I have to change my implementation of my view model?  In any case, how to get the selected item text of the drop down list?  Any hint?  Thanks a lot.

Create drop-down filter for External List

I hope this is an easy question. I will have an external list of a bunch of people.  There are several ways I want to display this data: All of them, Only the ones that have a value of 1-4 in the status field, Only the ones that have any other value in the status field, and people that have a value of 1-4 in the status field, but are at a certain location. I want to be able to put a drop-down filter above the list where people can select that. Could someone please point me in the right direction? Time is of the essence.  

Drop down list with description

i have create a form to register customer..i have a dropdownlist and i get the value from database and it's working good..now i want to add description in the same drop down list..How can i make it?where should i make changes

Change order for list view drop down

I may be overlooking something obvious, but I have not been able to find an easy way to sort the views available in the view drop down for lists.  We're migrating to 2010 from WSS 3.0 and currently, the view drop down is sorted alphabetically.   Help?

Autopostback on the last list in a Cascading drop down list series

Hi,First off I'm very new to Ajax for .NET.  I have a Cascading drop down list that is working fine to load the correct lists however I would like to have the last one initiate a query and display a datagrid on the same page containing the results of the query.  Without Ajax involved this seems rather easy by using autopostback on the drop downs.  If I could do it through Ajax that would be great but I can settle with having the page to reload to display the data.  Right now I'm not sure how to do either.  I enabled autopostback on the last drop down and wrote a method for it but I get an error at runtime saying:Invalid postback or callback argument So I'm really not sure what to do to get this to work right.Any help would be appreciated.Thanks,-Jordan

How to apply color to selected number of items in check box list and drop downlist

Hi all,    I want to apply color to selected number of items in checkbox list and seleted number of items in drop downlist for e.g color red for few items and black (default). I have a bit value set in data base so if bit is set to 0 then red and if 1 then back. Please help me.  

Browser enabled - Use One Drop Down List for Mutliple Drop Down List

I kind of have a cascading drop down, but I cannot figure out how to make filter all the other drop down list. I have seen this URL http://blueoceansassociates.wordpress.com/2008/11/19/cascading-drop-downs-in-infopath-web-forms-made-easy/, but is there a way to use only one Drop Down List as the dataconnection for all other drop down list. I have one drop down that needs to associate with 3 others. All 4 list point to a Sharepoint Secondary Data Source. Each drop down list is associated with the first drop down list choice. I have not seen this out on the web. Thanks for your response. chrisdoran

Drop Down List Selected Value problem ...



I created an Html Helper that renders 3 drop down lists (Day, Month and Year) for a field of type DateTime:

    public static MvcHtmlString Date(this HtmlHelper htmlHelper, String name, IEnumerable<SelectListItem> days, IEnumerable<SelectListItem> months, IEnumerable<SelectListItem> years, IDictionary<String, Object> htmlAttributes) {

      if (String.IsNullOrEmpty(name)) throw new ArgumentNullException("name", "Name cannot be null");

      StringBuilder fields = new StringBuilder();

      if (days != null)
        fields.Append(htmlHelper.DropDownList(String.Format("{0}.Day", name), days, String.Empty, htmlAttributes));

      if (months != null)
        fields.Append(htmlHelper.DropDownList(String.Format("{0}.Month", name), months, String.Empty, htmlAttributes));

      if (years != null)
        fields.Append(htmlHelper.DropDownList(String.Format("{0}.Year", name), years, String.Empty, htmlAttributes));

      return MvcHtmlString.Create(fields.ToString());     

    } // Date

And I have a DateFor extension:

    public static MvcHtmlString DateFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IEnumerable<S

Button sets value in drop down list



I want to make a button that changes the value in a dropdown list (dropdown populated from SQLdatasource)

This sounds strange i know but i have 4 dropdowns each hidden by panels, unless the preceeding dropdown's value is changed from it's initial value. So i make a selection from my first dropdown list & a postback occurrs triggering the next panel (and as such the dropdown list) to become visible, this occurs again until eventually my users will see 4 drop down boxes...(all required field vals etc)

As a result of this if at any point i change the value of my first dropdown back to '{Select}' then the other 3 i have all dissapear again, which s great - Effectively resetting my selection. I was thinking if i can create a button (which i'm going to call 'Reset) and make it change the first box's calue to '{Select}'...it would be ideal.

Anyone have any ideas?

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