Using a selection from a dropdown list to fill in a second dropdown list.


Hi,  I am new to the web programming area and looking for some help.  I have a situation where, like i said in my subject trying to base the list in the ddl2, to be based on the selection from ddl1.  What do i all need to include to do this.  As of now, I have two seperate SQL data sources, with the first one I have it just selecting from our database.  For the second list, I have a second sql data source that does a selection of a different column from teh same database but in the where clause have a parameter that will equal the selection from teh first..   i.e. select project from database A  and select class from database A where project = @ project.    Then the control ID for the parameter is the first dropdownlist..  IT is only returning 1 possible selection in my ddl2, and doesnt update when selecting a different one from ddl1.  I guess what am i missing, or what else do i need to include.?

0
skooks
10/31/2007 9:09:19 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

7 Replies
942 Views

Similar Articles

[PageSpeed] 29

See my post here: http://forums.asp.net/t/1176110.aspx

 It has an example of what you're looking for.


Mathminded
mathminded at hotmail dot com
0
mathminded
11/1/2007 1:29:17 AM

Hi

Here is an example.In the page load event

 protected void Page_Load(object sender, EventArgs e)
    {

 if (!this.IsPostBack)
        {

            SqlDataAdapter sqlAdapter3 = new SqlDataAdapter("SELECT * FROM [tbl_Categories]", cn);
            DataSet dset = new DataSet();
            sqlAdapter3.Fill(dset, "dss");
            DataRow dr3 = dset.Tables["dss"].NewRow();
            dr3["CategoryID"] = "0";
            dr3["Title"] = "------Categories------";
            dset.Tables["dss"].Rows.InsertAt(dr3, 0);
            ddlCategory.DataSource = dset.Tables["dss"].DefaultView;
            ddlCategory.DataBind();

 String result = ddlCategory.SelectedValue;
            SqlDataAdapter sqlAdapter4 = new SqlDataAdapter("SELECT * FROM [tbl_Products] WHERE [CategoryID] = '" + result + "'", cn);
            DataSet dset1 = new DataSet();
            sqlAdapter4.Fill(dset1, "dss1");
            DataRow dr4 = dset1.Tables["dss1"].NewRow();
            dr4["ProductID"] = "0";
            dr4["Title"] = "------Product Code------";
            dset1.Tables["dss1"].Rows.InsertAt(dr4, 0);
            Products.DataSource = dset1.Tables["dss1"].DefaultView;
            Products.DataBind();

}

protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
    {
        String result = ddlCategory.SelectedValue;
        SqlDataAdapter sqlAdapter4 = new SqlDataAdapter("SELECT * FROM [tbl_Products] WHERE [CategoryID] = '"+result+"'", cn);
        DataSet dset1 = new DataSet();
        sqlAdapter4.Fill(dset1, "dss1");
        Products.DataSource=dset1.Tables["dss1"].DefaultView;
        Products.DataBind();
    }

Hope that helps

Thanks & Regards


Mark as Answer if it helps you. Thanks
BISVN JSC COMPANY
0
a4nsd
11/1/2007 1:51:44 AM

a4nsd:
Here is an example.In the page load event

How is that different than my example?


Mathminded
mathminded at hotmail dot com
0
mathminded
11/1/2007 1:56:05 AM

 Ok... Thanks for your help, i had a stupid mistake and didnt have autopostback - to true... So that helps that problem.

 But i do have one more issue.  Im doing this within a gridview.. Its defaulting to 7 rows.  Im looking around and cant find a setting to set this so its either drastically larger, or better yet, to set it to 1 and then.. Ideally on selection of dropdown, or probably on a button click (add row button) is there a way to add another row to the gridview


 

0
skooks
11/1/2007 1:18:38 PM

skooks:

 Ok... Thanks for your help, i had a stupid mistake and didnt have autopostback - to true... So that helps that problem.

 But i do have one more issue.  Im doing this within a gridview.. Its defaulting to 7 rows.  Im looking around and cant find a setting to set this so its either drastically larger, or better yet, to set it to 1 and then.. Ideally on selection of dropdown, or probably on a button click (add row button) is there a way to add another row to the gridview

Hi skooks,

From your description, I understand that you want to know how to add a row to the grid view,
generally speaking, a grid view was used for binding a SqlDataSource, and you can use the
Insert Command of the SqlDataSource to insert a row to the data source and therefore the
grid view would been added a new row.

For more information about how to insert a new row to a grid view, please visit the following Web sites.
http://www.c-sharpcorner.com/UploadFile/Art%20Scott/GridViewInsertANewRow09012006165053PM/GridViewInsertANewRow.aspx

Hope this Information is helpful!

Xun


Regards,
Xun Ye.
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that
helps you, and to click “Unmark as Answer” if a marked post
does not actually answer your question. This can be beneficial
to other community members reading the thread.
0
Xun
11/2/2007 6:52:23 AM

Which is defaulting to 7 rows, the gridview or the dropdownlist?

 


Peter Brunone
MS MVP, ASP.NET
Founder, EasyListBox.com
Do the impossible, and go home early.
0
PeterBrunone
11/2/2007 2:43:44 PM

 Well the gridview is defaulting to 7 rows...   Here is my dillema.  I have info from a table i want to display in the gridview.. a product/op.system/release#/Old release#

I want the ones displayed to come from a the last release #.. So there will be a bunch of different products and op. systems...  But they also want it to be editible by dropdown.. SO i essentially want to show everything that was submitted in teh last release, but then if they want to change something just click on the product and scroll the dropdown to what they want to edit... 

0
skooks
11/12/2007 9:48:26 PM
Reply:

Similar Artilces:

Filling a dropdown list, based on a selection from another dropdown list
This seemed like a simple venture, and may be, but with my limited asp.net knowledge, I am having a problem... Basically, I have a page that is gathering information. I want a user to be able to select a value from a dropdown list... On Auto postback I would like to make a second listbox visible and bind data to it based on the selection from the first. (While keeping the value of the first listbox available) Right now I am filling my dataset with the tables used in the page load event and setting my second listbox.visible to false. in the SelectedIndex_change event of the first...

Cascading Dropdown List
Hi, First post so hello and need some help with an issue I have been dealing with.  I have an intranet page I created in ASP.NET using C# .NET 3.5 with a few Ajax Extenders including 3 Cascading Dropdown Lists. Now I have used the Cascading dropdown lists for my own purposes i.e they do not actually cascade their results to another dropdown list, the reason I did this was due to the having a User Control that contains an update panel and other bits i.e I didn't want the control/page posting page (something that happens when you click on a regular dropdown list). Everything is wor...

Hide dropdown list based on other dropdown list selection
Hi, i have an aspx page with a form. I want to hide dropdown list b depending on what is selected for dropdown list a. I need to do this client side Im new to this so any assistance would be appreciated. Thanks in advance   could you explai briefly about your requirements? you want to maske dropdownlist b as invisible if you select any item on dropdownlist a? or you want to make it invisible for a specific item?   Hi,     Change the visibility of dropdownlist as false on selected index change. Private Sub ddl_a_SelectedIndexChanged(ByVal sender As Syste...

How to get value from first dropdown list to second dropdown list
Hi Does soneone know hot to get value from first dropdown list to second dropdown list or remove it from seond dropdown list? I have a web form page. On the page, there are two dropdown lists, one Add button, and one Remove button . First dropdown list has four list items. Second one does not have list item yet. When select a item from first dropdown list, then click "add" button. I want it to apear in the second dropdown list without reload the page. Or select item from second dropdown list, and click "Remove" button. it will remove from second list. Please help. &nb...

Selection in one dropdown list effecting the visibility of another dropdown list
I have two drop down lists. They are not databound. We'll called them dropdownlist1 and dropdownlist2.Basicly, I want people to choose an object in the first dropdownlist. Depending on their selection, it will make certain items in dropdownlist2 invisible.Currently my thought is to have something in the lines of the following (In the dropdownlist1 - SelectedIndexChanged - Postback being set to Auto)if dropdownlist1.text = "Such and such" then(this is where I would declare which options are available)However, I do not know the proper syntax of saying make the following item...

Problem with 2 dropdown lists (second dropdown list reset automatically)
My Question is pretty simple.I have two dropdown lists. Once I clicked on one then second one gets populated (through SelectedIndexChanged and with AutoPostBack = true) now I am selecting the value in the second dropdown list and then hitting submit button. I am now sending these values to another page. but hte value in second drop downlist is always selected the first value (though i have selected the item other than first one)I am loading first dropdownlist in page load and under (if (!IsPostBack){ } )This is very silly things happening any bdoy has any idea about this or faced the same pr...

Populate dropdown list based on selected value in another dropdown list
I have a datagrid (grdCar) that contains two dropdown listboxes (ddlCarManf and ddlCar). When the user clicks the "Edit" link and places the grid into edit mode, they select a value in ddlCarManf. Based on the selected value in ddlCarManf, I need to then populate ddlCar with a list of cars for which the selected manufacturer makes (I'm using ddlCarManf.SelectedValue to query the database).  I bind my datagrid in the page_load event as: If Not Page.IsPostBack Then    BindGrid() End If Here is my control (ddlCarManf) as is appears within grdCar in ...

one dropdown list affecting another dropdown list vb.net
I am desgining a website using VB.NET wherein the data items of one dropdown list depends on the selection of a data item in the previous dropdown list something similar to selection of country USA from 1st dropdown list...triggers 2nd dropdown with list of states in USA How can this be accomplished.... Any help will be appreciated... Thanks & Best Regards... hi boy,first I suggest turn on auto postback on first dropdownlist. In select index changes(first dropdownlist) - select value on second dropdownlist My blog is here.Please remember to 'Mark as Answer' i...

automatically generating content in a dropdown list based on the selection of another dropdown list
hi i currently have a "categories" dropdown list i'm using to help filter data in a datagrid (have it setup using data and table adapters). i've introduced another dropdown list (called subcategories) to filter the datagrid so it only displays records that fit in both the category and subcategories.it all works fine, but i'm wanting to set it so the subcategories dropdown list gets generated on the client-side depending on the category selected. does anybody have any quick tutorials or a quick explination on how i could do this? am i missin...

is there a property for teh dropdown list that allows someone to use a dropdown list as a textbox and a dropdownlist?
is there a property for teh dropdown list that allows someone to use a dropdown list as a textbox AND a dropdownlist?  Or is there another control that I can use to do that? I guess I am looking for a combo box like VB.Net has? I want the user to be able to input characters in the dropdown list. There is an AJAX Toolkit extender called AutoComplete which extends a TextBox control such that it calls a web service as you type and forms a dropdownlist below the textbox with acceptable options.  See:http://www.asp.net/AJAX/AjaxControlToolkit/Samples/AutoComplete/AutoComplete.asp...

Populate second dropdown list from first dropdown's selection
I want to do something that should be fairly simple.  I want dropdownlist B(users) to populate after the selection of dropdownlist A(projects).  How would I go about doing this?  Both dropdownlists are populated from a sql server database.  Thanks first, disable the second ddl.  populate the first on load.  when the selected index event fires on the first ddl, enable the second ddl and populate it. If you're using ASP.NET, you need to either set AutoPostBack property to true for a full post back, or set AutoPostBack to true and use AJAX Update panel for Async...

Dropdown list bound to another dropdown list
I have two dropdown lists on my page. The first contains a list of names and the second contains a list of hardware devices. My problem is: When i choose a name from the first dropdown i need the second to become populated with their related devices. This works fine, however if i then change the name in the first dropdown list, it adds another set of devices to the devices dropdown list. The way i want it to work is to refresh the devices dropdown when the name is changed. So that only that persons related devices show up (in the second dropdown)  Any help would be much apprecia...

Filter dropdown list from another dropdown list
Help Please!!! I am trying to filter the data in a dropdown list from information chosen in another dropdown list. 1st table has modification types, 2nd table has modifications. When the user chooses the modification type needed, then only those modifications should appear in the 2nd list. mydata7 = New SqlDataAdapter("Select * from ModificationList ", myconnection) ds7 = New DataSet mydata7.Fill(ds7, "table") Dim dr7 As DataRow ddlModification.Items.Add("Please select Modification ...") ...

populate a dropdown list on the basis of other dropdown list
I need to populate a dropdown list on the basis of other dropdown list. Both dropdwon list are datasourced with SQL datasource. I tried the SQL datasource where query . but it will need a post back. I dont want my form to be postback. I guess this is what AJAX is for but i really dont know how to get this with AJAX in a simple and quick way..... or it is not simple and quick ????Mark as answer if anybody's post has helped you It can be simple and quick.  See this video:http://www.asp.net/learn/ajax-videos/video-77.aspx And also the tutorial on how to use the Cascading Dropdow...

Web resources about - Using a selection from a dropdown list to fill in a second dropdown list. - asp.net.web-forms

Selection - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Cricket: ACT Comets selection trial unearths young talent pushing for Futures League spots
... Creek Molonglo fast bowler Joe Slater (3-31) also stood up, catching the attention of Comets senior coach Kyle Piper. "Each of the selection ...

Jury selection to begin for Tim Bosma murder trial
Jury selection is set to begin today in Hamilton at the trial of two men accused in the death of Tim Bosma. Police say Bosma left his home on ...

Lloyd Carr Among 4 Named to College Football Playoff Selection Committee - Bleacher Report
Four new members were appointed to the College Football Playoff selection committee Thursday, including former University of Michigan head coach ...

Jeff Long no longer chair of College Football Playoff Selection Committee
Arkansas athletic director Jeff Long's tenure as chairman of the College Football Playoff Selection Committee will end after two seasons.

Jury selection set in fatal 2014 Bourbon Street gunfight - Fox News
A trial is scheduled to begin in New Orleans for the only person arrested following a 2014 gunfight on Bourbon Street that left a bystander dead ...

AP PHOTOS: A Selection of Pictures From the Past Week
AP PHOTOS: A selection of pictures from the past week

Lloyd Carr, Rob Mullens, Jeff Bower, Herb Deromedi named to College Football Playoff selection committee ...
Former Michigan coach Lloyd Carr, Oregon AD Rob Mullens, ex-Southern Miss coach Jeff Bower and former Central Michigan coach Herb Deromedi will ...

College Football Playoff Selection Committee Appoints Four New Members
The College Football Playoff Selection Committee appointed four new members on Thursday, as reported on by ESPN . Former University of Michigan ...

Rashida Jones Sings & Stars In Boss Selection's 'Flip & Rewind' Music Video
... executive producer Jo Miller of Full Frontal . Rashida recently teamed up with her nephew Sunny Levine for his brand new project Boss Selection ...

Resources last updated: 1/22/2016 1:55:38 PM