.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 select a name from dropdownlist using c# code?

Posted By:      Posted Date: August 28, 2010    Points: 0   Category :.NET Framework

More Related Resource Links

Dropdownlist appears to be null in code behind


I have a weird problem...

I have a web part form, with one of the dropdownlist, when referenced in code behind, happes to be null.

Common.bindMultiChoices(ddlPly4, oEnquiriesList, "Ply 4 Type (Paper)", "Select Ply 4", null); 

But at front user control file, I do have:

<tr><td><asp:DropDownList ID="ddlPly4" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlPly4_OnSelectedIndexChanged" /&

Clear a DropDownList from code behind.

Hi All,I want to clear the value of DropDownList from codebehind and i have found followingsolution.ddl.Items.Clear(); andddl.DataSource=null; ddl.DataBind();Now the question is which is the best solution and why?

Select Item from Dropdownlist


I have a dropdown list created via MVCContrib FluentHTML - how do I perform a postback when the user selects any item in the dropdownlist? 

How to add Select Control parameters in Code Behind


I have a need to add my page controls dynamically in code behind.

I do well, adding a dropdownlist, a SQL datasource to populate it, setting it to autopostback=true, and adding a gridview and its SQL datasource.

What I'm unsure about is how to programmatically refer to the SelectParameter, being a control (the DropDownList), and its selected item.

any ideas? 

better code for select in a typized dataset


hi there
i have a dataset in my project named  DS.xsd
so, i usually take a dataTable using this code:

        Dim da As New DSTableAdapters.RistorantiTableAdapter
        Dim DT As New DataTable("Ristoranti")
        Dim DR As DS.RistorantiRow()

        DR = da.GetData.Select("codRistorante=" & HID_Risto.Value)
        Dim drr As DS.RistorantiRow = DR(0)

        With drr
            If .IsCAPNull = False Then TXT_Cap.Text = .CAP
            If .IsCategoriaNull = False Then TXT_Categoria.Text = .Categoria

i think it is obsolete code
and i use 5 rows of code for take my data
is it correct? or may i use another approach for doing it better?

AJAX DropDownList won't populate.. error500.. code is working though.


Here's what I have.  I was able to debug and traverse through the webservice and return teh array back into the first call method of: return new CarsService()..  But back in the page_load method, I can't get it to update and show up in the page.  what am I doing wrong?!?!


<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
                    <cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="DropDownList1"
                     Category="Make" PromptText="Please select a make" LoadingText="[Loading makes...]"  

Items added through Javascript to a dropdownlist are not accessible through code behind


Hi All,

I am successfully able to add new items to a drop down list using Javascript.

The script I am using is 

        function FillJavaScriptValues() {
            var ddlDeliveryVan;
            ddlDeliveryVan = document.getElementById("DropDownList1");
            var opt = document.createElement("option");

Select the current value in a dropdownlist using XSL and SharePoint


I'm using the row edit template below. The problem I have is that the current value is not selected when the row edit XSL template is used. The value defaults to the first item in the list. What is the best way to get the current value to be the selected item in the template below? I thought having DataValueField="{@type}" and DataTextField="{@type}" would resolve the issue, but it does not.

<asp:DropDownList runat="server"  id="ff3{$Pos}" 
 DataValueField="{@type}"  DataTextField="{@type}"  
</asp:DropDownList > 

Dropdownlist postback always select first item


Hello, I am new at Asp.net. I hope some experts can help me.

I have 2 dropdownlist controls (ddl1 and ddl2). When I pick an item from ddl1, it will update ddl2. The problem is when I pick an item in ddl2, it always selects the first item in the list. Is it that the ddl2 autopostback causes the first ddl1 to reload and results the ddl2 to be refreshed also? Or I didn't set something correctly?

thanks in advance.


<asp:DropDownList ID="ddl1" runat="server" DataSourceID="sql

Populating DropDownList in FormView from Code Behind


On my formview I have a drop down list that is populated with the names of the files in a certain directory. This works fine, but when the drop down list selected value is bound to the database field I get the following error :

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

I have setup other drop down lists in the same formview populated from SqlDataSources and these all work fine. I can see perhaps why this is an issue because I have not specified a DataValueField or a DataTextField for this drop down that is populated in code (whereas I can for the SQL bound ones) because I'm not sure what these settings would be.

I need to have a "blank" option as well so that the field does not default to the first value in the list.

My code (I have stripped out some meaningless controls) :

<asp:FormView ID="FormView1" runat="server" DataKeyNames="BannerID" DataSourceID="SqlDataSource2" OnItemDeleted="FormView1_ItemDeleted">
    <table width="100%" cellspacing="0" cellpadding="4">                          

SQL SELECT in my code which doesn't like 2 words


SELECT * FROM tblstock WHERE Devicestatus=('Active') AND Model like '%"&criteria &"%'

The statement above is a snippit from my code. My problem is that the search won't understand a space between say two words.?

so if the user puts in DELL COMPUTER it won't return anything!?  But if they put in DELL on its own it finds the record that says DELL COMPUTER?!!

I'm just a bit confused that's all... Anybody know how I can get around this?

Many thanks

DropdownList in which value I select drops in to the textbox



When I try to use this code in a Form View, I get an error message:

Compiler Error Message: CS0103: The name avgift_namnTextBox is not in the current context
ROW: 35

Rad 33: if (dropDownlist.SelectedValue == "Other")
Rad 34: {
Rad 35: avgift_namnTextBox.Enabled = true;
Rad 36: avgift_namnTextBox.Text = string.Empty;
Rad 37: avgift_prisTextBox.Enabled = true;

Here is my code: Anyone know?

<%@ Page Title="Lista medlem" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="medlem.aspx.cs" Inherits="medlem" %>

<asp:FormView ID="FormView3" runat="server" DataKeyNames="faktura_id"
                DataSourceID="SkapaFaktura" DefaultMode="Insert" Width="687px">
                    <table style="width:

Populate a dataGridview based on select an item in dropdownlist!


Hello all!

In window form,  there are two comboBoxs named cbo1, cbo2 with populate the same items in the dropdownlist as following: For examples,

Class A

Class B

Class C

I like to populate the data into two dataGridViews named dgv1, dgv2 based on selecting an item in two dropdownlists. The rules is if I select an item in the cbo1 to populate data in dgv1, and cbo2 with hide (remove) an selected item from cbo2 to avoid that the user selects the same item for populate the same data in the dgv2. In a brief, the displayed data in two dgv1, dgv2 are different. Any helps in C# code, I really appreciate it. Thanks in advance.

What is the code to say if the select statement of sqldatasource1 control has no record, then..


What is the code to say:-

 if the select statement of sqldatasource1 control has no record, then..

Pls help... thanks




Gridview not updating when SQL has select statement in code behind


I have a gridview with a sql datasource. When the select statement for the datasource is in the sqldatasource control then everything works fine and i can view the data and update it through the gridview. When I take away the selecet statement and insetad use a sqldatasource.SelectCommand in my code behind then I can only view the data in the gridview but cannot edit. When I try to edit/update data the data being edited goes back to original and the gridview stays in edit mode. After hitting cancel on the gridview then the old data still shows. Any ideas about this? "Optimistic Concurncy" is also switched off so that is not the problem.

Code Optimized Web Development Profile (VS 2010 and .NET 4.0 Series)

When you first run VS 2010 it prompts you to select an IDE profile to use. The profile you select will configure how tool windows are displayed/docked in the IDE by default and set the default keyboard shortcuts. You can then customize any of these settings by using the Tools->Options menu within the IDE and then override/change them. You can also later reset your profile and pick a different one by choosing the Tools->Import and Export Settings menu command.

Free Code Snippets - ASP.NET

You Can Find Useful ASP.NET Related Posts on the above link.
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