Stuck trying to automatically populate three text fields based on value selected in gridview dropdown list


When I click on the gridview edit button and select a value from the ComponentID DropDown list I would like fields, tbxFunctions, tbxFuncFail, and tbxFailMode to be updated with the information that matched the ComponentID from tblFailures:

Question 1) do I need to create an object data source or sql data source to get functions, funcFail, and failMode by ComponentID 

Question 2) Not Sure how to set the text property to for tbxFunctions, tbxFuncFail, and tbxFailMode.  Do I add a Select Parameter statement below? 


<asp:ControlParameter ControlID="ddlControlID" Name="ControlID" PropertyName="SelectedValue" Type="String" />



ComponentID int 4

SubSystemID int 4

Component nvarchr 60

ComponentDesc nvarchr 150

Inactive bit 1 


FailureID              int 4

ComponentID       int 4

 Functions        nvarchar    255   (tbxFunctions)

FuncFail            nvarchar         255     (tbxFuncFail)

FailMode        nvarchar  255  (tbxFailMode) 



DropDownList Component: ddlComponent

<asp:TemplateField HeaderText="ComponentID" SortExpression="ComponentID">


<asp:Label ID="lblComponent" runat="server" Text='<%# Eval("ComponentID") %>'></asp:Label>



&nbsp;<asp:DropDownList ID="ddlComponent" runat="server" OnDataBound="ddlComponent_DataBound" DataSourceID="cpddlODS" DataTextField="Component" DataValueField="ComponentID">

</asp:DropDownList><asp:ObjectDataSource ID="cpddlODS" runat="server" OldValuesParameterFormatString="original_{0}"

SelectMethod="GettblComponentBySubSystemID" TypeName="tblComponentBLL">


<asp:ControlParameter ControlID="ddlSubSystem" Name="SubSystemID" PropertyName="SelectedValue" Type="String" />



<asp:RequiredFieldValidator ForeColor="white" ID="valddlComponent" runat="server"

ErrorMessage="Cannot leave the ComponentID selection blank" Text="*" Display="Dynamic"




<asp:DropDownList ID="NewComponent" runat="server">






Text Fields To Be Updated

<asp:TemplateField HeaderText="Functions" SortExpression="Functions">
                    &nbsp;<asp:TextBox ID="tbxFunctions" runat="server" Text='<%# Bind("Functions") %>'></asp:TextBox>&nbsp;
                    <asp:Label ID="lblFunctions" runat="server" Text='<%# Bind("Functions") %>'></asp:Label>
                    &nbsp;<asp:TextBox ID="NewFunctions" runat="server"></asp:TextBox>&nbsp;

 <asp:TemplateField HeaderText="FuncFail" SortExpression="FuncFail">
                    <asp:TextBox ID="tbxFuncFail" runat="server" Text='<%# Bind("FuncFail") %>'></asp:TextBox>
                    <asp:Label ID="lblfuncFail" runat="server" Text='<%# Bind("FuncFail") %>'></asp:Label>
                    <asp:TextBox ID="NewFuncFail" runat="server"></asp:TextBox>

            <asp:TemplateField HeaderText="FailMode" SortExpression="FailMode">
                    <asp:TextBox ID="tbxFailMode" runat="server" Text='<%# Bind("FailMode") %>'></asp:TextBox>
                    <asp:Label ID="lblFailMode" runat="server" Text='<%# Bind("FailMode") %>'></asp:Label>
                    <asp:TextBox ID="NewFailMode" runat="server"></asp:TextBox>


Question 3) 

Code Behind - Trying but need some direction and do I need to tie in a query to get and display the records that match the ComponetID value ?

Protected Sub ddlComponent_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

 If ddlComponentID.SelectIndex <>-1 Then

 tbxFunctions.text = ddlComponentID.SelectedItem.Text

tbxFuncFail= ddlComponentID.SelectedItem.Text

tbxFailMode= ddlComponentID.SelectedItem.Text

End If

End Sub


Thank you,



3/10/2008 8:00:18 PM 72751 articles. 1 followers. Follow

5 Replies

Similar Articles

[PageSpeed] 27

Hey Ptown,

sorry to ask you like this, please clarify to me regarding what you are trying to acheive . this is what i understood from your post,

you have DDL in a gridview, you want to select something from that DDL say for example EmpID( employee id) and based on that value , you want to generate 3 textboxes say like EmpName, Age, Salary. are the textboxes inside the grid or outside.

please correct me if i am wrong.

Thanks a lot

Keyboard not found. Please Press < F1 > to RESUME

Please Remember to Mark as Answer for the post(s) that help it can help others......Thanks
3/10/2008 10:49:34 PM


3/10/2008 11:08:51 PM

Hello and thank you,

I have a ddl in gridview called ddlComponetID.  When you select a value from ddlComponentID say for example ComponentID 1 (3.6v Battery Pack) then TextBoxes Make, Model, and SerialNumber will be filled in instead of typing in the information.  I found an articl that is similiar, but it is for a details View,  I want to do the same thing but for gridview.  I am having difficulity changing the systax for gridview.  This is what I have and the system does not like it, I'm trying.


Protected Sub ddlComponent_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

Dim cpddl As DropDownList = CType(sender, DropDownList)

Dim myDetailsView As DetailsView = CType(cpddl.NamingContainer, DetailsView) '  Dim gvRow As GridViewRow = DirectCast(cpddl.NamingContainer, GridViewRow)

If myDetailsView.CurrentMode = DetailsViewMode.Edit Then

'   If e.Row.RowType = DataControlRowType.DataRow AndAlso e.Row.RowState = DataControlRowState.Edit Then


"ComponentID", cpddl.SelectedValue)

Dim gv As System.Data.DataView = CType(GetFailureInfoDS.Select(DataSourceSelectArguments.Empty), System.Data.DataView)

Dim tbxF As TextBox = GridView1.FindControl("tbxFunctions")

Dim tbxFF As TextBox = GridView1.FindControl("tbxFuncFail")

Dim tbxFM As TextBox = GridView1.FindControl("tbxFailMode")

tbxF.Text = gv(0)("Functions").ToString

tbxFF.Text = gv(0)("FunctionalFailures").ToString tbxFM.Text = gv(0)("FailureModes").ToString

End If

End Sub

3/10/2008 11:09:21 PM

i'm sorry the text boxes are in the grid

3/10/2008 11:17:07 PM

issue resolved

3/12/2008 4:35:20 AM

Similar Artilces:

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

Populating dropdown list based on dropdownlist selected value on gridview edititemtemplate
I have 2 dropdown lists in a gridview. While editing the grid I want to populate the EditTask dropdownlist based on the selected item value of the EditProject dropdownlist. I have functions to populate both dropdown lists in the code behind.I have created an event DropDown_SelectedIndexChanged which will fire on changing the project dropdownlist but can't find a way to populate the tasks based on the selected project.   Can anyone help please?    <asp:TemplateField HeaderText="Project" ItemStyle-VerticalAlign="Top&q...

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, (U/C)--------------------------------Mark it as ANSWER if it Helps U   Check out this link with co...

problem with selected text field and selected value field in check box list
Hi! i have a  problem with check box list:here is the code for binding the check box list with sqldatasource  SqlDataSource1.SelectCommand = "select vcentrolno,inttpaperno from tabmarksdetails where vcbunchno='" & strBunchNo & "'"  chkEnrolNos.DataBind()say now my chkEnrolNos consist of data in this way:vcentrolno        inttpaperno selected text   selected valueA11439            1A11439            2AR439    ...

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

Populate gridview based on drop down list selected value
I have a dropdown list populated with table names. After a tablename is selected from the dropdownlist, my grid view should be populated. I am trying to assign String Var = Convert.ToString(dropdownlist1.selectedvalue ); In select statement,:"Select * From " +Var but this is not working.  How should i do this. ThanksGans      Hi, gvenkat:Here is the sample of appending the parameters to the sqlcommand statement. I have no idea about  your senario but hope this helps you to the right direction . If you still have the problem, maybe you can d...

Dropdown list and tying in the selection to populating 5 other gridview / repeater controls
On one page I have a drop down control that is tied to my backend sql database via a sql data source control.   Based off of the selection that the user makes I want multiple gridviews (4 to be exact) and 2 repeaters to populate with their information.   Now those 6 controls are getting their info from other sql data source controls on the page -- how can I use a parameter control on my select statments and relate it to the SelectItem.Value of my drop down list that the user first selects when they come on the page.   As always guys thanks for your help - ...

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

Error Populating a textbox in the Gridview Item Template Row based on a drop down list selected value
Hello, I would like to Populate a textbox in the Gridview Item Template row based on a drop down list selected value.  Right now I have the basic gridview where I have to click on the edit butio to update each row.  To get around the single row edit, I decided to move the edit fields to the Item Template Row where the databound fields are in edit mode when the page opens so I can perform a bath update.  The only problem is that the ddlComp_SelectedIndexChanged works when the page is designed to edit the a single row at a time.  Since I move the fields to th...

Password text value gets deleted when value selected from Dropdown list
Hi, I need help in my dropdown control, this is what my problem is I am using DropDown List in my aplication in a form and i want to show some default selected value in the first drop down D1 and depending on values selected in D1 the values gets displayed in the child drop down D2. My issue is i have a password texbox before getting valued from D1 and D2......when i select value from D1 the password enetered in hte password textbox in password mode gets deleted. so every time he user types the password and then select something in the dropdown, he has to ...

Displaying values from 3 textboxes automatically after selecting a value from a dropdown list
 The dropdown list is databind to a sqldatasource from the Bike Table.After selecting a bike Name from the dropdown list, the status and rent price will be displayed on the 2 textboxes automatically.Both the status and  rent price values are taken from the same Bike Table.Can anyone help me with this?Thanks. On the selected index change property of the dropdownlist hit the database to get the details (status and rent ) for the selected Item and set the values to the text of textboxes.Hope this helps. Just do this in your OnSelectedIndexChanged event of the ddlSqlCommand cmd =...

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

Populate a second drop down list upon selection value of the first drop down list in a gridview
How to Populate a second drop down list upon selection value of the first drop down list in a gridview? DropDownList1 ******************* <asp:TemplateField HeaderText="SystemName" SortExpression="SystemName">                <EditItemTemplate>                    <asp:DropDownList ID="sysidddl" runat="server" DataSourceID="sysods1"    &nbs...

populating the dropdown list with the values from the data base, Failing near adding the values todropdown
Here is My code' .aspx &nbsp;<asp:DropDownList ID="ddlkeyword" runat="server" Width="204px" >   </asp:DropDownList></td>   .aspx.cs   page_load() { fillddlkeyword(); }private void fillddlkeyword() {string StrSql = "Select distinct(formName)as formName from tbl_form"; oDB.RunDBQuery(StrSql, out oRS);DataTable dt = new DataTable(); dt.Columns.Add("Form");if (oRS.HasRows) {while (oRS.Read()) {DataRow dr = dt.NewRow(); dr["Form"] = oRS["formName"].ToString(); &n...

Web resources about - Stuck trying to automatically populate three text fields based on value selected in gridview dropdown list -

Facebook Users Automatically Checked In To Events They RSVPed Yes To
A reader tipped us off that Facebook is automatically checking in users at events that they RSVPed they would attend. continued… New Career ...

Now Users Can Remove Contacts Automatically Saved by Facebook’s Friend Finder
Two weeks ago, many Facebook users began asking questions about curiously good recommendations suddenly appearing in Facebook’s “People You May ...

App Store - Gmail inbox software to efficiently manage emails, automatically send/upload ...
Get Gmail inbox software to efficiently manage emails, automatically send/upload files to cloud storage(Dropbox, Box, and G Drive), ...

Automatically organize your desktop icons into shaded areas called Fences! - YouTube
Fences® is the most popular desktop organization tool used by millions of users worldwide. Create shaded areas called "fences" to automatically ...

CSAIL fixes software bugs automatically, in any language, by copying from safer applications
A new system can repair bugs in software using smart processing that imports functionality from other programs, all without access to source ...

Emailing porn at work not automatically sackable, court finds
Australia's federal court has upheld a ruling that emailing pornography in the workplace is not automatically a sackable offence.

Shazam iPhone app now listens for music, TV shows automatically
Shazam has updated its iPhone app to tag songs, TV shows and more on its own, no longer requiring users to open the app and tap a button.

App of the day: Human for iPhone automatically tracks your movements
Human for the iPhone is an activity tracker that automatically distinguishes between different types of movement.

iPhone 5 automatically rotates using Cycloramic App. - YouTube
[NEW VIDEO] Cycloramic 2.0 update teaser vid with panoramic photo preview: Cycloramic has been Awarded ...

Resources last updated: 11/25/2015 8:37:21 AM