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


Top 5 Contributors of the Month
satyapriyanayak
Kaviya Balasubramanian
SP
abhays
Sasi Prabhu
Post New Web Links

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

Posted By: Venkat     Posted Date: February 13, 2010    Points: 2   Category :ASP.Net
 
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


View Complete Post


More Related Resource Links

stop postback if selected value in dropdown list = No

  

Hi All,

I want to stop postback if a certain value from a ddl is selected.

I've used VB to create a page whereby if a certain value from a ddl is selected then a hidden panel becomes visible. The problem is the likely answer to a majority of my ddl's is 'No' (or a no type response), however, even though the panel visibility remains false upon selecting No a postback still occurrs, the page refreshes and moves back to the top. I suppose this is a question with 2 possible solutions (or 2 questions rather)

1: Is there anyway of setting postback to false if selected value = No? A typical example of how my code appears is below

    Protected Sub ddlYesNo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlYesNo.SelectedIndexChanged
        If ddlYesNo.SelectedValue = ("1") Then
            panel3Days.Visible = True
            PanelWhoWasInjured.Visible = True
        Else
            panel3Days.Visible = False
            PanelWhoWasInjured.Visible = False
        End If
        radbut3DY.Focus()
    End Sub

(i've used the value '1' to represenet Yes)

2: Is there a way of setting the page position after postback? As you can see in my code above i've set the focus on the next control (being a Radio Button) but i mean, is there

Databound dropdown list inside detailsview filtered dependent on selected radiobuttonlist item

  

It's driving me mad.  I have a detailsview bound to an sqldatasource. One of the items on the data table is to get its value from a dropdown list, so I created a template field and entered a dropdownlist, then bound that to a second datasource with the selection values in it. As the values can be male or female related, I have an unbound radiobuttonlist above the dropdownlist with two values - male or female - retunring an d"m" or an "f" and I want to use this to filter the records coming from the second data source for the dropdownlist.

I can't use a normal SQL control parameter on the datasource as the selector (the male/female radiobuttons) are in the detailsview and therefore "invisible".  I set up a normal control parameter with "none" as the type.  I then set the "autopostback" value to "true" for the male/female radio buttons and tried writing in the code-behind for the "maleorfemale_SelectedIndexChanged" event and using debug lines revealed that I was getting the "m" or "f" I needed by using "findcontrol", so that's fine.

I also tried adding in the "selecting" event for the second datasource to use the value of the radiobutton item, but although the "selecting" event fires

Dropdown List in Gridview - While saving the record in gridview the droppdown selected index are cha

  

Friends,

I am developing page for maintaing employee record using Visual Studio 2008, MS SQL server 2005.

I am able to fetch and display all the employee information in gridview, the gridview have the dropdown list to display the employee type [ Part Time, Full Time, Permanent , Contract ], in the item template i am having dropdown list. IN the dropdown list i am displaying this.

But While saving the record in gridview the droppdown selected index are changed to 0 of other dropdown list.

the user may be change the dropdown value from permanent to contract, or so. but while click on the save button in gridview, all the previous selection are gone, and always showing the first record of dropdown list. I know this is happening because we are doing dropdown list bind on onRowDataBound.

But i want to retain all the user selection in gridview, please help me how to do this.

thanks in advance.






how to get selected value of dropdown list

  

Hi,

i am assgining an values to drop down list using javascript onchange event of another drop down.

every thing is working fine,but when i try to get the value of selected dropdrown it is giving me nothing

as my dropdown declare as fallows


                            <asp:DropDownList ID="DDLSeller" runat="server" Width="150px" onchange="LoadLotNoList()">
                            </asp:DropDownList>
                            <asp:DropDownList ID="ddlLot" runat="server" Width="150px">
                                <asp:ListItem Value="Identification No."></asp:ListItem>
                            </asp:DropDownList>

and javascript as fallow
try {
                    $.ajax({
                        type: "POST",
                        url: "../service/TWWebService.asmx/WebMethod",
                        data: varData,
                        contentType: "application/json; charset=UTF-8",
                        dataType: "xml",
                        success: function (msg) {
                            LotNoList.children().remove();
                            LotNoList.append

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.Items.Clear()
        Me.DropDownList1.DataTextField = "Link"
        Me.DropDownList1.DataValueField = "LinkURL"
        Me.DropDownList1.Items.Insert(0, New ListItem(" - Select - ", 0))
        Me.DropDownList1.DataSource = allLinks
        Me.DropDownList1.DataBind()


 

 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
   System


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

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.

Cheers


Attach Workflow to Task List, don't get option to manually start workflow via dropdown on task item

  
Hi,

 

I am running WSS 3.0 with other workflows which are functioning correctly.  I created a new workflow in Visual Studio 2008 and was able to successfully run it in my dev environment.  I attached the workflow to a task list in my dev environment and was able to manually start the workflow by using the drop down workflow option and using the menus to manually start it.  I installed this workflow in our production environment and attached it to the task list (which had a SPD workflow attached to it which stopped working about a month ago).  I made sure that the option to manually start the workflow was checked.  When I tried to manually start the workflow, (hover mouse over title, drop down) there isn’t a workflow option.  The workflow also will not start automatically when a task is changed.

 

I attached this same workflow to a different task list in production and get the option to start it.

 

I have tried creating a small workflow in SPD 2007 and attaching it to the task list.  It shows that it is attached, when I look at the workflows that are attached to the task list, but I still don’t get the option to manually start it.

 

I have checked my security and I have fu

How to tie a dropdown list from a nother table to a dataview in sharepoint designer

  

hi,

i created a dataview for a user table to insert new records. now i have to use a dropdown list that get data from another table. to insert in my user table. in the user table only the code is stored. but i need to get that code description that is in another table in my dropdownlist to choose from in my dataview.

how can i do this in sharepiont designer2007?


how to hide/display controls in NewForm.aspx based on dropdown value in SharePoint list

  

Hi,

I have 1 dropdown in my sharepoint list with other columns. If dropdown value equal to 'xyz' i need to display some other controls, otherwise these controls should be hidden.

I know we can achieve this with javascript. If any one can provide code or sample then it will be appreciated. or is there any other alternative methods to do this ........


Thanks & Regards, Neerubee

Retain DropDown,TextBox's previously selected values after redirected from another page.

  

 Hi People, How are you all doing?

I have 2 pages one is SearchPage & It has DropDowns, textboxes to specify the search criteria. From the search result the user is redirected to another page when he clicks the hyperlink in the search result  where he fills in the information and again redirected to SearchPage. Now the SearchPage is posted back with no state i just want to retain the search criteria and display when user comes back. Please give me some suggestion how to get this done. I've used ViewState to save the values and check them in Page_Load but they are null.   

Thanks

Abid

 Update: I've come up with this code. But the problem is The values are being retained but the Button_Click event is not being handled properly. When i Check the code even after this "DropDownList1.SelectedValue = Session["Name"].ToString();" DownList1.SelectedValue is EMPTY"" samw with DropDownList2 . please Suggest something

 

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsControlsEmpty())
        {
            if (SessionExist())
            {
                DropDownList1.SelectedValue = Session["Name"].ToString()

Need to remove databinding of DropdownList when another dropdown list changes

  

I have many controls on my form, but in particular, I have 2 dropdownlists.  1 dropdown list has 2 values, and each value controls what the second dropdownlist displays.  This is an edititemtemplate and both dropdowns have the selecteditem set via '<%# Bind("fieldname") #>' on page load.  

THe problem is, if I change the value of the first dropdown, it errors out because the second dropdwon has a bound value that is no longer acceptable. 

Can I cancel the bind of the second control, if the the first one is changed?  I would like to cancel the bind, and update the values by using a different datasource depending on the value of the first dropdown or hardcode the new values.

 

Currently.

If Dropdown1 has a value of "A" for example Dropdown 2 Shows Values "1", "2", "3"

If Dropdown 1 has a value of "B" , Dropdown2 Shows Values "4", "5", "6".

It binds fine initially, but if I change Dropdown1 from A to B, I want Dropdown2 to show the new values, maybe with a default of "Select an Item" and not error out b/c it's attempts to bind a value of 1, 2, or 3.

 

Hope this makes sence, b/c I'm

Categories: 
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