Can I populate a Dropdown list in a GridView from another Dropdown list

Hi there,

I have a Gridview control that contains 2 DDLs. The first one is populated on page load (from a Generic list in the code behind) and is working with no problems. I want to populate the 2nd DDL by making a selection in the first DDL which in turn would call a DB method and cause a postback.

I've tried using the "OnSelectedIndexChanged" method for the DDL and the "FindControl" method for the 2nd DDL, but the GridView can't find it on Postback and throws an error. I've also tried using the "onSelectedIndexChanged" method for the GridView but also with no luck.

Suggestions anyone...?

0
Moneypenny
4/26/2008 8:01:54 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

2 Replies
924 Views

Similar Articles

[PageSpeed] 54

The Method will be like this
1. You will rise a selectedindexchanges method for the firstdropdownlist.
2. when event fires,in the code
 
 for(int vLoop=0 ; vLoop<gridview1.rpws.count ; vLoop++)
 {
  Dropdownlist ddl1 = gridview1.rows[vloop].findcontrol("dropdownlist1") // here dropdownlist1 is the id of the dropdownlist that you have given in itemtemplate
  if(ddl1=(dropdownlist)sender)
  {
   Dropdownlist ddl2 = gridview1.rows[vloop].findcontrol("dropdownlist2") // here dropdownlist2 is the id of the dropdownlist that you have given in itemtemplate  
   // Now do your database manipulations
  }
 }
 

Here in this method, check whether ddl1,ddl2 are nulls or not.
if they are nulls, that means, you are giving the name providing
in findcontrol method is wrong. then check the itemtemplate of
that column for the dropdownlistname


Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
0
ramireddyindia
4/26/2008 9:08:18 AM

Hi ramireddyindia,

Thanks for your reply, I've tried the code and it works fine. Thanks very much for your help, you've saved me alot of time

Moneypenny

0
Moneypenny
4/27/2008 1:50:07 AM
Reply:

Similar Artilces:

Populate a Dropdown List based on the value of another Dropdown List
 Hi ALL,    I have two Dropdown List.I need to Populate second Dropdown List based on the value of first Dropdown List.I am n't using Update Panel.Pls suggest me RegardsSri ASP.NET AJAX Cascading DropdownDarrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you!   just populate second dropdown in SelectedIndexChanged event of the first dropdown. Muhammad ShoaibSoftware Engineer,Lahore, Pakistanwww.heartofpakistan.com (U/C)--------------------------------Mark it as ANSWER if it Helps U   Check out this link with co...

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...

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...

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...

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...

Gridview Filter using Dropdown where dropdown is populated from a distinct list in the Gridview
I have a report page that shows the user who accessed pages, when they accessed it, and the page they accessed.  I have it attached to some dates, so they can easily filter the search down.  What I want to do is to further filter the list with a dropdown of users, so they can see which user viewed what pages over a certain time frame.  I know how to query the database for a list of users and then populate the dropdown with all the users...then attach that dropdown to the sqldatasource for the gridview to filter it down by user.   But, what if I just want to popu...

Populating and Implementing 4 Dropdown lists on web form through web service
Hi all, I have a Project due after one week. It is a web service project. I have a Web Form which communicates to the web service and this web service communicates to the database. I have all my SQL statements in the Data Acess Layer to create more secure web service application. The Web service class is also in the Data Access Layer. I need to populates the 4 Dropdown list boxes on the web form from one table. I have Customer table which contains information About CustomerName, CustomerType, Address, City. These 4 colum values should populate the 4 Dropdown lists. And then I need to implem...

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...

Can a DropDown list populate a Gridview??
I'm trying to create an easy way to navigate through the records in my gridview, I currently have about 100 record, and I have the paging on my gridview set to 10 per page. Currently if I'm searching for a certain record I have to guess which page and then select the record I want to display in the Detailsview. Is there a way to create a dropdown list above the Gridview, the dropdown list could contain employee names, when you select a name only that record shows in the gridview... Is that possible? or is there a better way to search for a certain record quickly? Yes you can easily...

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...

How to populate list from other dropdown list
Hey guys, Let say there are two groups 1) Car  2) Airlines.  Car has different company name say 1) Honda, 2) Toyota, 3) Nissan.  Airlines has say 1) American, 2) US Airways, 3) Continental 4) America West. Now, could you please give me some idea, that I want to make two dropdown list,  one dropdownlist  shows Car and Airlines and another dropdown list shows list of only selected value from the first dropdownlist. Now , on the first dropdown list when I select Car, in the second list only list of car company should be listed. Similarly when I Sel...

can i drag the selected value of dropdown list in one web part to another web part
hi, supose i am having time displaying in on webpart can i drag the value of time to another web part and and display the time is: and the value draged from the other webpart so i want to drag the value year and population into antoher web part and according to that the grap must appear i.e what  i exactly want is i must drag some value from one webpart to onother webpart and according to event some thing must happen in another web part   Hi, The problem has been replied in the following post: http://forums.asp.net/t/1141884.aspx But from the title you described, do ...