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

Post New Web Links

How to set selected value on asp:dropdownlist?

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :SharePoint
I am not a dev, I am sharepoint admin.  I have a SPD page with an asp:dropdownlist that uses a sqldatasource to populate the drop-down list.  This list does a postback which allows the user to select an item in the list and the rest of the page is generated based on the selection.  The user has options which include navigating away to another page with the id from the select passed as a query string to the new page.  This all works fine.  I am not using any bound fields or SSO for this because I need to execute a stored proc on the server to obtain the items populating the drop-down list. What I need to do now is allow the user to navigate back to the original page, however I want the original page to display using the same id passed in a query string rather than the default value of the datasource.  (so they don't have to select the same item from the drop-down list again after returning to the original page)  I can't seem to find a way to do this.  When I add a SelectedValue to the asp:DropDownList I get an error saying the Bind is not allowed.  I "thought" that I could add a querystring parameter to the datasource and use it as the selected value, but have not been successful.  I don't know if I am just doing it wrong or if this concept is wrong.  Below is the relevant code for the dro

View Complete Post

More Related Resource Links

how can i display the selected value of dropdownlist from edittemplate to label from itemtemplate?


I have a detailsview with a dropdownlist in it. the detailsview is connected to a database table(employees having the following fields: id-smallint,name-nvarchar, departmnet-smallint). the ddl is connected to another table (departments with the following fields: id-smallint, departmentName-nvarchar). the ddl is in the edititemTempalte of the department field. My goal is to display in  the itemtemplate the departmentName (the selected value from the edititemtemplate ). How can I do this? Doyou have any ideas?

thanks a lot

dropdownlist - default value is not 'selected value'

i have created a dropdown list that is populated from a sqlserver datasource. i have a separate sql command which uses the dropdownlist.selected value as a parameter and returns the command value to a label.  it mostly works fine but with one problem. when the page loads, the label value is null, because it doesn't seem to treat the dropdownlist default value as a selected value. when i use the dropdownlist to select a value, this is fine and the label begins to display the expected value. is there anyway I can make the default value when the page is loaded act like a manually selected value, so the label control never displays a null value?

ASP.Net MVC Dropdownlist and selected value problem

I was able to create a dropdownlist for my MVC project, but the value is not selected as  selected value on the dropdownlist. It just shows whole county list from the first.The value is from database. I tried find it from previous post, but it was quite confusing. Please, suggest me for any idea. Controller Code public ActionResult Edit(int i) {      var items = new SelectList(db.MST_COUNTRies.ToList(), "COUNTRY_ID", "COUNTRY_NM");      ViewData["MST_COUNTRies"] = items; } View Code <p>     <%= Html.DropDownList("COUNTRY_ID", (SelectList)ViewData["MST_COUNTRies"])%> </P>I was able to create a dropdownlist for my MVC project, but the value is not selected as  selected value on the dropdownlist. It just shows whole county list from the first.The value is from database. I tried find it from previous post, but it was quite confusing. Please, suggest me for any idea.Controller Codepublic ActionResult Edit(int i){     var items = new SelectList(db.MST_COUNTRies.ToList(), "COUNTRY_ID", "COUNTRY_NM");     ViewData["MST_COUNTRies"] = items;}View Code<p>    <%= Html.DropDownList("COUNTRY_ID", (SelectList)ViewData["MST_COUNTRies"])%></P>

Fill a Listbox with value selected from a Dropdownlist

Hi, Maybe the question has already be posted, but I didn't find it.I have in my web page two controls: a dropdownlist and a listboxMy goal is to fill the listbox with values from my database depending on what I have selected in my dropdownlist.I wouldlike to use the CascadingDropDown component for that. Is that possible ??(I tried on my own and I get this error messageException Details: System.InvalidCastException: Unable to cast object of type 'System.Web.UI.WebControls.ListBox' to type 'System.Web.UI.WebControls.DropDownList'.I think it's when i tried to fill the listbox with this function:[WebMethod] public CascadingDropDownNameValue[] GetAppliForDomain(string knownCategoryValues, string category) { int domainID; //this stringdictionary contains has table with key value pair of country and countryID StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); if (!kv.ContainsKey("Domain") || !Int32.TryParse(kv["Domain"], out domainID)) { throw new ArgumentException("Couldn't find Domain."); }; SqlConnection con = new SqlConnection(strConnection); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text

How to get item selected in dropdownlist

I'm searching and trying now for the last couple of hours, so I thought the community might help.I'm filtering the rows in a gridview using a ddlDate. Now, I want to request this selected item.But: When I load the page without clicking in the DropDownList, the ddlDate.SelectedValue is empty, and the ddlDate.SelectedItem.Text.ToString() gives a NullReferenceException.Is there any way to fix this without using a listbox?

Fetching DropDownList Selected Value

I'm having issues getting the selecteditems and value after Databinding a dropdown list.  I have a button event with dropdownlist2.Selecteditem.text, but will always get the "-- Select --" as the SelectedItem.text ?  Anybody know why this is happening ?   Dim conn As New SqlConnection '("xxxxxx") conn.ConnectionString = ConfigurationManager.ConnectionStrings("PostAdSqlServer").ToString Dim query As String = ("SELECT [CategoryId], [Name] FROM [Category]") Dim cmd As New SqlCommand(query, conn) cmd.Connection.Open() Dim ddlValues As SqlDataReader ddlValues = cmd.ExecuteReader() DropDownList2.DataSource = ddlValues DropDownList2.DataValueField = "CategoryId" DropDownList2.DataTextField = "Name" DropDownList2.DataBind() DropDownList2.Items.Insert(0, "-- Select --") cmd.Connection.Close() cmd.Connection.Dispose()    

dropdownlist selected item problum

In gridview we have edit button whenever user click edit button i want to show particular data of dropdownlist as a selected data that is selected by user as a selected text of dropdownlistis there any solution ???

Selected Option from dropdownlist

 I need to figure out a way to modify the style property of a div on my page so that when a certain item ("Not shown - please quote") on a few different dropdownlists are selected,  the div style is set to "display: none". The dropdownlist gets generated dynamically and the amount of dropdownlists varys for each product. I've named the class via the cssclass property in the dropdownlist template usercontrol to be "dropDownClass".Here is my code for this page: <div id="ProductControls"> <div id="ProductOptions"> <div id="ctl00_MainContentHolder_VariantsDisplay_VariantsPanel" class="variantsdisplay"> <table> <tr class="dropdownlist"> <td class="choicelabel"><span id="ctl00_MainContentHolder_VariantsDisplay_modifierTemplate1_InputLabel">Color</span></td> <td class="choicefield"><select name="ctl00$MainContentHolder$VariantsDisplay$modifierTemplate1$ModifierList" onchange="javascript:setTimeout('__doPostBack(\'ctl00$MainContentHolder$VariantsDisplay$modifierTemplate1$ModifierList\',\'\')', 0)" id="ctl00_MainContentHolder_VariantsDisplay_modifierTemplate1_ModifierList" clas

How to Capture a DropDownList Selected Index Change Event

I have a gridview that receives data based on selection from a primary dropdownlist object. Works. Within the gridview, there is a dropdownlist whose selected index is based on the query from the primary dropdownlist. Works. Problem. How do I force the used to  change whatever value that the dropdownlist contains after they make their initial selection from the primary dropdownlist; except the default value of "Please make a selection". Gridview, contains a checkbox which drives whether a selected row is inserted into the data base. The databind in done using an ObjectDataSource on the presentation page, not in the code behind.   Thank you.   Ayomide 

dropdownlist selected value problem

i have dropdownlist<%= Html.DropDownListFor(model => model.SchoolDistrict,Model.sSchoolDistrict) %>To Poulate this value i have below code in controllerslist = new SelectList(list, "ID", "Name", selected);but what ever selected value i pass didnot shown in ddl

Howto add selected item from dropdownlist to a textbox on the same form?


 I have been trying to figure out what the proper method is to be able to have a dropdownlist on the same form that holds a number of textboxes for properties. I am using a strongly typed typed view which was generated by the Visual Studio IDE so it contains textboxes for all of the properties of my strongly typed class.  The class has a few properties that can have a set of possilbe answers; I'd like to displat those possible answers in a dropdownlist and then when the user fills in the form and clicks the submit button the selected item would be transferred to the correct property. I have a solution but think there must be a better solution out there and was wondering if anyone might point me in the right direction.

So say I have a model with 3 properties, FirstName, LastName. and MaritalStatus.

If I generated a view for this then I'd get an aspx file with the following:


    <% using (Html.BeginForm()) {%>
        <%: Html.ValidationSummary(true) %>

            <div class="editor-label">
                <%: Html.LabelFor(model => model.FirstName) %>

set selected value after jQuery populated Dropdownlist



i'm using jQuery to populate an cascading dropdownlist. But i want to set a selected item after jQuery filled the DDL with items.

How do i do that?


Dropdownlist is accepting 'selected', but isn't rendering that option as selected


I thought this would be pretty simple, and in fact it's working on another dropdownlist on the same View, so I'm hoping I missed something very small that is easy to fix. Here's my code:

<% List<SelectListItem> activeListItems = new List<SelectListItem>();
                           activeListItems.Add(new SelectListItem { 
                                Text = "Select Status",
                                Value = ""
                           activeListItems.Add(new SelectListItem
                               Text = "Active",
                               Value = "1",
                               Selected = (Model.Active == true)
                           activeListItems.Add(new SelectListItem
                               Text = "Inactive",
                               Value = "0",
                               Selected = (Model.Active == false)

                        <%: Html.DropDownListFor(model => model.Active, activeListItems) %>
                        <%: Html.ValidationMessageFor(model => model.Active) %>

When I

Beginner question: get selected value of Html.DropDownList


Hi everyone, how are you doing!

I'm just started learning MVC 2. I went through the music store example (though I don't 100% get everything). Now I want to add some functions to the page to learn more. I added paging, and now I want to add search combo boxes (drop down lists). Basically, in the album list screen, I want to add 1 drop down list of genre. If user select 1 genre then click Search, the page should show all album of that genre only.

My problem is I don't know how to get the selected value of this drop down list. The approach I am using now is to get the selected value, then put it as parameter and redirect to Index (/StoreManager/Index?searchGerneId=x). I searched through many posts but couldn't find a solution that works for me. It is probably because I don't really get MVC yet and still try to do things the code-behind way. So please help me :) My code  for Index in Controller is below

public ActionResult Index(int pageNumber = 1, int searchGenreId = -1)
            var albums = from album in storeDB.Albums
                         join genre in storeDB.Genres on album.GenreId equals genre.GenreId
                         join artist in storeDB.Artists on album.ArtistId equals artist.ArtistId
                         orderby album.Title
                         select al

Accessing the selected value of a dropdownlist control in a Form View


I need to verify the selection in a dropdown list control is not a certain value.  It is in the edit mode of a formview.

just to verify that I could access it I tried to put the value in a label,  however it is always empty:


this is what I used

  'Dim droplist5 As DropDownList = DirectCast(FormView1.Row.FindControl("DropDownList5"), DropDownList)


            LabelHeaderwarning.Text = droplist5.SelectedValue.ToString


I also tried the validation controls but they don't seem to work with a drop down control.


Any suggestions on this would be extremely helpful



How to save DropDownList selected value


Hi all,

How can I save dropdownlist selected value? (mabey into cookie?)
I have a language selection dropdown, but on page reload it resets te value.

Can anyone help me? Innocent


Gr. Danny

cannot have multple items selected in a dropdownlist


I have a webpage with two dropdownlists. I am not selecting anything from the dropdownlist and even if i debug code it does not show any error but still its generating the error.

"CAnnot have multiple items selected in Dropdownlist"

Here is my code.Please help me out this is very urgent!

Imports System.Data
Imports System.Data.SqlClient
Imports FESecurity
Partial Class MarketingReports
    Inherits System.Web.UI.Page
    Dim con As New SqlConnection
    Dim sql As String
    Dim cmd As New SqlCommand
       Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
                con.ConnectionString = "server=;database=;uid=;pwd="

        Master.MyStyleSheet = "osx2.css"
        Master.MyTabs.LoadTabItem("MarketingMain.aspx", "", "Marketing")
        Master.MyTabs.LoadTabItem("MarketingAdmin.aspx", "", "Marketing Admin")
        Master.MyTabs.LoadTabItem("MarketingReports.aspx", "", "Marketing Reports")
        Master.MyTabs.LoadTabItem("EngineeringMain.aspx", "", "Engineering")
        Master.MyTabs.LoadTabItem("EngineeringAdmin.aspx", "", "Engineering Admin")
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