VB.NET - DataGrid edit mode: how to have one dropdownlist populate based on value selected in previous dropdownlist

I have a DataGrid (see code at end of my question) with several
dropdownlist controls within TemplateColumns for Editing.  For the
first 2 ddls in my grid, ddlMedType and ddlMedicationName, I would like
to populate ddlMedicationName based on the selecteditem of ddlMedType,
but I don't know how to reference this.

Thank you for saving me from confusion!!!!

Here is my DataGrid code:
NOTE: I've bolded the 2 controls that I need help with -- the rest you can really ignore!!
<asp:datagrid id="dgMeds" runat="server" OnEditCommand="dgMeds_EditRow" OnUpdateCommand="dgMeds_UpdateRow"
    OnCancelCommand="dgMeds_CancelRow" AutoGenerateColumns="False" Visible="False">
        <asp:BoundColumn DataField="medid" ReadOnly="True" HeaderText="MEDID"></asp:BoundColumn>
        <asp:BoundColumn DataField="subjid" ReadOnly="True" HeaderText="Subject ID"></asp:BoundColumn>
        <asp:BoundColumn DataField="visitnum" ReadOnly="True" HeaderText="Visit #"></asp:BoundColumn>
        <asp:TemplateColumn HeaderText="Medication Type">
                <%# DataBinder.Eval(Container.DataItem, "medtypename") %>
                <asp:DropDownList ID="ddlMedType" Runat="server" DataTextField="textname" DataValueField="code" DataSource="<%# GetMedTypes() %>" SelectedIndex='<%# GetSelectedIndex_MedTypes(Container.DataItem("medtype")) %>' AutoPostBack=True />
        <asp:TemplateColumn HeaderText="Medication Name">
                <%# DataBinder.Eval(Container.DataItem, "medicationname") %>
                <asp:DropDownList ID="ddlMedicationName" Runat="server" DataTextField="textname" DataValueField="code" DataSource="<%# GetMedicationName() %>" SelectedIndex='<%# GetSelectedIndex_MedicationName(Container.DataItem("medicationname")) %>' />
        <asp:BoundColumn DataField="dosemg" HeaderText="Dose"></asp:BoundColumn>
        <asp:TemplateColumn HeaderText="# Pills/Patches">
                <%# DataBinder.Eval(Container.DataItem, "numpillspatchname") %>
                <asp:DropDownList ID="ddlNumPillsPatch" Runat="server" DataTextField="textname" DataValueField="code" DataSource="<%# GetNumPillsPatch() %>" SelectedIndex='<%# GetSelectedIndex_NumPillsPatch(Container.DataItem("numpillspatch")) %>' />
        <asp:TemplateColumn HeaderText="Frequency">
                <%# DataBinder.Eval(Container.DataItem, "freqname") %>
                <asp:DropDownList ID="ddlFreq" Runat="server" DataTextField="textname" DataValueField="code" DataSource="<%# GetFreq() %>" SelectedIndex='<%# GetSelectedIndex_Freq(Container.DataItem("freq")) %>' />
        <asp:TemplateColumn HeaderText="Route">
                <%# DataBinder.Eval(Container.DataItem, "routename") %>
                <asp:DropDownList ID="ddlRoute" Runat="server" DataTextField="textname" DataValueField="code" DataSource="<%# GetRoute() %>" SelectedIndex='<%# GetSelectedIndex_Route(Container.DataItem("route")) %>' />
        <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" HeaderText="Edit" CancelText="Cancel"

4/12/2006 1:37:39 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 18

4/12/2006 5:50:27 PM

Similar Artilces:

populating a dropdownlist of states based on selection of country in dropdownlist and populating a dropdownlist of cities based on selection state in state dropdownlist
My code is this but i m not getting states in dropdownlist of states based on selection of country and  cities based on selection of state <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"><title>Untitled Page</title> </head> <...

Populate second DropDownList values based on first DropDownLists "SelectedValue" when FormView is in Edit Mode.
My FormView is getting its detail based on the selection in the Master Gridview control.The form subsequently loads its data, and when in edit mode it displays 2x DropDownLists. One is "Country", and the other is "State". Naturally the second DDL will depend on what the parent item is in the first DDL.I am hoping to find this so that I can preload the correct items in the 2nd DDL. I am hoping to accomplish this with as little code as possible, as I am using StronglyTyped DataSets and ObjectDataSource.cheers  try the following url, which is using AJAXhttp://aspalliance.com/716_Populati...

How Select one dropdownlist value using down arrows corresponding other dropdownlist value are select
I am using two dropdownlist box.One is used for country selection. other one is used for state selection.I am using dropdown selectedindexchanged event. when i click country dropdownlist corresponding state is selected in state dropdownlist box. How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.R.Karthikeyan   kartmca: How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.Generally, we don't implmenet...

using a button (in vb.net) to launch a new page based on dropdownlist selection
Hi, I am creating a page for my students for my personal website. I teach piano, and I would like to set up a site where my students can see assignments/personal grades based on their login. Once they login, my site will launch and on the homepage, there is a dropdownlist of three items representing level of study: Beginner, Intermediate and Advanced. If the student selects "Beginner" from the dropdownlist, they click the "submit" button and the "Beginner" page will launch listing items unique to them (the unique items are based on their individual log...

updating label text based on selected item in a DropDownList (LINQ, VB.NET)
Hello experts,Quick question for you: I'm writing a form that loads an XML file as an XDocument and populates the items in a DropDownList based on a field in the XML structure.What I would like to do is change the text on certain labels in the form based on what is selected in the DropDownList. I've got the first part of this down, but am having trouble getting the label text changed. Any assistance you can give me is appreciated.Here's the XML file: <Errors> <SubErrorCode> <Number>-82</Number> <ErrMsg>Lorem</ErrMsg> <WIH>I...

Populate DropdownList based on selection of other DropdownList in DetailsView
Hi, All     I have two dropdownlists in a detailsview control called (ddlLeagues and ddlTeams). I want to be able to filter the teams by ddlLeagues. I use 2 objectdatasources to populate the dropdownlist controls. The method i have gone for is to use the find control method to get the ddlLeagues selectedvalue so i can pass the objectdatasource a  required LeagueID, which returns me the teams for that LeagueID. If i databind the detailsview control the required teams are shown in the teams dropdownlist for the selected LeagueID. The ddlLeagues goes back to the o...

on selecting country from one dropdownlist ...states of selected country is not getting populated in second dropdownlist
 hi iam having a dropdownlist which loads the country names on page load....my problem is wen i select india the corresponding states are not coming in another dropdownlist my code isi have two tablescountryname:countryid identity,countrynamestatename:stateid identity,statename SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings["con"].ToString());       protected void Page_Load(object sender, EventArgs e)    {                   &...

populate second dropdownlist based on value of first dropdownlist
 I have two dropdownlists.one dropdownlist contains countries and second states.i get the the countries and states from back end sql server 2005.after getting countries and states i put them in cache in global.asax and bind it to two dropdownlistsnow what i have to do is. my two dropdown's contains ALL.when i select ALL in countries dropdown i need to get all statesbut when i select certain country i should get only states belong to that country.So i have to apply row filter.all the countries and states are in the same dataset.can some one tell me how to do that.i can show you my co...

Populate Dropdownlist using VB.NET
 Hi, Please help me,How can i populate a Dropdown list using code behind (VB.NET)??thanks JFRBPH12™  dropdownlist1.datasource = ds;dropdownlist1.datatextfield = "your display field";dropdownlist1.datavaluefield = "your value fieed"; dropdownlist.databind();http://www.codersource.net/asp_net_dropdownlist.html Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever. Hi  Try this sample :Partial Public Class Clock    Inherits System.Web.UI.Page    Protected Sub Page_Load(ByVal sender As Obje...

problems populating a dropdownlist in vb.net
Today i bought vb.net... help this is hard.... I can't populate a 'dropdownlist', in the aspx file i've assigned the datasource, datatextfield and the datavaluefield to the dropdowlist, but how do i bind the data to the 'dropdownlist'? Am i right in thinking that specifying the datasource, value and text in the '.aspx' file does not automatically produce the code to bind it in the code behind file (aspx.vb)? Do i have to hard code it into the page_load sub? or can i getl VB.NET to do it somehow? If so... can anyone write me some example code. I've had VB.NET do the connection, ad...

Populating GridView based on value selected from a dropdownlist
Hello All, I have two user controls.  The code is as follows: 1) UCTitles: ******************************************************************************** Markup is as follows: <%@ Control Language="VB" AutoEventWireup="false" CodeFile="UCTitles.ascx.vb" Inherits="UCTitles" %> <asp:SqlDataSource ID="sdsTitles" runat="server" ConnectionString="<%$ ConnectionStrings:pubsConnectionString5 %>" SelectCommand="SELECT [title], [price], [pubdate] FROM [titles] WHERE ([pub_id] = @pub_id)"> <SelectParameters> <asp:FormParameter DefaultValue="0" FormField="txtS...

How to Dynamically populate 2nd Dropdownlist based on the 1st Dropdownlist value in GridView ?...
Hi, I have two template column wiht DropDownList, I neet to populate 2nd DropDown on selection of 1st DropDown. could you pls tell me with sample of code.Please remember to click “Mark as Answer” on the post that helps youJasim AkhtarNew Delhi ( INDIA ) See here: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/CascadingDropDown/CascadingDropDown.aspx  here is a nice tutorial about it.http://www.odetocode.com/Articles/231.aspx hope this helps Muhanad YOUNISMCSD.NETMy Blog || My Photos || LinkedIn miazaidi:I have two template column wiht DropDownList, I neet to populate 2nd Dr...

populating items in dropdownlist box based on a selection from another dropdownlist box
I need to populate the respective states from the states dropdownlist when a user chooses a country from the country dropdownlist. Similary when the state is selected from the states dropdownlist the corresponding cities should get displayed in the cities dropdownlistbox. Pls provide me with the coding? Here is the following code which i developed. Code:====Private Sub fillcountry()        ddlcountry.Items.Add("India")        ddlcountry.Items.Add("UK")        ddlcount...

Populating One DropDownList from the other DropDownList
Please note this is one way to perform the task and NOT THE ONLY WAY <font color="red"> Please use stored procedures instead of Ad-Hoc queries to protect your application from Sql Injections </font> private void Page_Load(object sender, System.EventArgs e) { if(!Page.IsPostBack) { SqlDataAdapter ad = new SqlDataAdapter("SELECT CategoryName,CategoryID FROM Categories",myConnection); DataSet ds = new DataSet(); ad.Fill(ds,"Categories"); ddList.DataSource = ds; ddList.DataTextF...

DropDownList selected value determines value of second DropDownList
I have a quick question that I'm sure has been addressed before, but I can't seem to find a solution. I have two drop down list fields: startTime and endTime coded as such: <asp:DropDownList id="startTime" runat="server"> <asp:ListItem Value="00:00">12:00 A.M.</asp:ListItem> <asp:ListItem Value="00:30">12:30 A.M.</asp:ListItem> <asp:ListItem Value="01:00">1:00 A.M.</asp:ListItem> <asp:ListItem Value="...

Web resources about - VB.NET - DataGrid edit mode: how to have one dropdownlist populate based on value selected in previous dropdownlist - asp.net.presentation-controls

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 11/28/2015 4:46:38 AM