Updating values of dropdown lists on a page based on a textbox value

Hi Everyone,

 I know from the title this seems simple however there is a twist.  I have a page that a user fills out to submit feedback on products.  To keep data clean, I let them select the product, type and size based on dropdown lists, but also want to make it so if they type in the barcode, the values for the Product, Type and Size are looked up and populated on the form for them to see it before submitting the form. The form has several textboxes and dropdown lists that update using SQLDataSource connections.  The problem that I'm running ito is the following:

I have two Input Fields:

Barcode (textbox) and ProductCode (dropdownlist)

I have Two other fields:

ProductSize, ProductCategory (both dropdownlists)

Here is what I'm doing.

If the user clicks the ProductCode field, he can pick a value and the ProductSize and ProductCategory dropdowns refresh and display the appropriate values.  Then the user can pick his selection of these two fields and he's on his merry way to submit the form.

 However, I'd like to set it up so that if the user enters a value into the Barcode box, upon updating the field, the ProductCode, ProductSize and ProductCategory fields all get values assigned to them based on a SQL lookup to the product database.

Since I have SQLDataSource connections to the three dropdownlists, I don't think I can assign another one to them to pull values based on the Barcode and not the ProductCode.  What I was thinking of is to create code in the BarCode textbox textchanged event to pull the values from the SQL table and then assign them to the listboxes.  I think it's fairly simple however I'm not that greate with VB.Net and here is what I have, but I dont' know how to assigne it to a value so then I can assign it to the dropdownlists:

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

 

 

Dim complaintDataSource As New SqlDataSource()
complaintDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("complaintConnectionString2").ToString()

complaintDataSource.SelectCommandType = SqlDataSourceCommandType.Text

complaintDataSource.SelectCommand = "Select pclass from products where ([barcode] = @barcode)"

complaintDataSource.SelectParameters.Add("barcode", BarCode.Text)

complaintDataSource.Select()

 

End Sub

If I just leave the "ComplaintDataSource.Select()" line like that, it tells me I'm missing arguments.  What I'd like to find out is how can I evaluate the selection and assign it to a string value that later I can assign to one if the dropdownlists.

 Sorry to be so long, but this seems to be simple in concept but I'm new to this whole thing and the MSDN help seems to confuse me more than help me. 

I'm basing all this code on my submit button that has the following code in it to submit the form:

 

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

Dim complaintDataSource As New SqlDataSource()

complaintDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("complaintConnectionString2").ToString()

 

complaintDataSource.InsertCommandType = SqlDataSourceCommandType.Text

complaintDataSource.InsertCommand = "INSERT INTO feedback (LName, FName, Address1, City, State, Zip, IPAddress, Entered, EmailAddress, Comment, Product, SubProduct, Code) VALUES (@Lname, @FName, @Address1, @City, @State, @Zip, @IPAddress, @Entered, @EmailAddress, @Comment, @Product, @SubProduct, @Code)"

 

complaintDataSource.InsertParameters.Add(
"LName", LName.Text)

complaintDataSource.InsertParameters.Add("FName", FName.Text)

complaintDataSource.InsertParameters.Add("Address1", Address1.Text)

complaintDataSource.InsertParameters.Add("City", City.Text)

complaintDataSource.InsertParameters.Add("State", State.Text)

complaintDataSource.InsertParameters.Add("Zip", Zip.Text)

complaintDataSource.InsertParameters.Add("IPAddress", Request.UserHostAddress.ToString())

complaintDataSource.InsertParameters.Add("Entered", DateTime.Now)

complaintDataSource.InsertParameters.Add("EmailAddress", EmailAddress.Text)

complaintDataSource.InsertParameters.Add("Comment", Comment.Text)

complaintDataSource.InsertParameters.Add("Product", Product.text)

complaintDataSource.InsertParameters.Add("SubProduct", SubProduct.Text)

complaintDataSource.InsertParameters.Add("Code", Code.Text)

 

 

Dim rowsAffected As Integer = 0

 

Try

rowsAffected = complaintDataSource.Insert()

 

Catch ex As Exception

Server.Transfer("ReturnPages\EntryError.aspx")

Finally

 

complaintDataSource = Nothing

 

End Try

 

If rowsAffected <> 1 Then

Server.Transfer("ReturnPages\EntryError.aspx")

End If

End Sub

 

Thanks for any feedback.

John

0
deverdits
5/3/2009 2:26:08 AM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

0 Replies
682 Views

Similar Articles

[PageSpeed] 50

Reply:

Similar Artilces:

Drop down list in Form view returns error when value in bound field (data binding
I get the following error when I click edit to edit the details in the web form:'ddlUserRestrictionType' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: value  I would like it to accept any value which currently exists in the database. Is this easily achievable? With what you've posted, all I can tell is that you are trying to set the SelectedValue of a ddl to a value that does not exist in the list.  It would be helpful if you can post some code and the expected values of this control.~ Timwww.bucketo...

How to show value in textbox from selected value in Dropdown list
I have two text box, txtbox1 should be from two field for example i have one dropdownlist where i select item and another txtbox2 i want to put value, when i first time to write manually value in txtbox2 in and selected item from ddl i want to result in concatenate from in txtbox1. for example  I haveif not me.ispostback thenDim cm as new sqlcommand("Select AccMjrid, Names from Accgrp", me.sqlconnection1.open())me.sqldataAdapter1.fill(Dataset1, "Accgrp") Me.cmbAccMajID.DataSource = Me.DataSet11.Tables("AccMajor") Me.cmbAccMajID.DataTextField = "AccName" Me.cmbAccMajID.DataValueField ...

Selecting a Value in a Drop Down List Based on the Value of a Textbox
I have a formview control (.NET 2.0/VS2005) in which users enter company contact information.  When a user enters a postal code in the appropriate text box, the territory for that company needs to be calculated and displayed in a territory drop down list. I know how to calculate and retrieve the territory from my SQL Server database, but I can't seem to nail down how to trigger the code and don't want the user to have to click a button. I tried using the OnTextChanged event, but that doesn't seem to be what I want because I need this calculation to be performed pri...

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

Getting a value from a SQL table displaying a specific page based on that value
May seem to newbie but here goes:I have a login page.  For the login I run a stored procedure with 4 return values, 0 - being valid, 1 - username exists already, 2 - username is incorrect3 - password is incorrectThis all works fine.  But from that I have the default page when the login credentials are correct.  The issue is I need to display a specific default page based on their location id from the member table which I already run a sp against for the login.  I have set up an .ascx page with a datagrid to display the results which works when I run the query for a h...

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

I want to display textbox on changing value of dropdownlist or selected value of dropdown list.How could i?
for example i have taken field PF%,PF($)  in dropdown.Onselected value of % i will show textbox.In which u can fill  the value of PF% based on that calulation will be shown in other textbox. But how can i do thta? Not too sure I undertand your question, but if you want to show/hide elements here's a few things you might want to try: You can set the dropdown's autopostback to true and perform all sorts of wonderful serverside stuff, including adding a textbox control (with a certain value) to a container div. If you want to keep things light then use some CSS and ...

updating textbox based on values on other textbox
i have a user control with a set of 5 textbox and label.I load it 2 times dynamically in page1.aspx.So 2 row of a given set gets created on webpage.I need to show the sum of the values entered in box1,box2,box3,box4 into the txtbox5.So as soon as the user enters the values in of those 4 text boxes,i want txtbox5 to get updated simultaneouly.On the button click,i insert the data of all these textboxes and label text from both the row to DB.I am not able to do the 'simultaneous' updation of txtbox5 ,as soon as the text changes in any of those 4 textboxes..Can anyone guide me on this?.....

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

Problem using sql query with dropdown list and textbox values?
I am writing a query to search through a database table.I get the search value from the text box and the column name from dropdownlist and display the results got in a gridview. In SQL the query example is select * from tbldetails,information_schema.columns where information_schema.columns.column_name='firstname' and firstname='lee';whereby, I get the details from the table having records which match the search criteria, that is ;column name=firstname and firstname value='lee' My asp.net coding involving data adapters,data set is as follows:1 Dim sda As ...

Populate two textboxes based on the values of a Dropdown List Using AJAX
 Hi All,    This is my first AJAX application.I want to Populate two textboxes based on the value of a Dropdown List Using AJAX.Pls guide me on this. RegardsSriRam Hello SriRam, Here are a few resources: http://aspalliance.com/716_Populating_a_DropDownList_using_AJAX_and_ASPNET.4 http://roshanbh.com.np/2008/09/change-textbox-value-dropdown-list-ajax-php.html http://www.w3schools.com/HTMLDOM/prop_option_value.asp This last one here is the code:<html><head><script type="text/javascript">function alertValue()  {  var x=document.g...

How to use values from two dropdown lists to get the value for a third dropdown?
I have three dropdown lists.  One for Office, one for Department, and a list of employees.   There is no relationship in the database between office and department.  The relationships are to the employees.  What I need to do is take the selected values from Office and Department, and run a query to get the list of employees who match both parameters (Office & Department).  Here's my code for the three dropdown lists.  How do I "connect" Office & Department to populate employees?  code from my vb.net page    for the ...

DropDown List DataSource for Options *AND* for DataSource Value in Database?
  I have a DropDown object list and so far I can set it to EITHER: 1) A SINGLE value (From table A using DataSource1)2) Multiple value options (From table B using DataSource2)  But how do I set both of the above? (i.e. set it to the value of option DataSource1 but allow the user to set it to any value in DataSource2)  Thanks ! wht do u mean?? binding dropdown to one datasource containg ds1 and ds2??Please remember to "Mark As Answer" if this post answered your question!Bilal Shouman - MCAD.NET|My Blog|--------------------------------- you can only bind...

Web resources about - Updating values of dropdown lists on a page based on a textbox value - asp.net.sql-datasource

Wikipedia talk:Updating information - Wikipedia, the free encyclopedia
This is brilliant! It would probably work best for elections etc in minor locations. For something that's well-known like a US predidential election, ...

8 Tools For Updating Facebook Offsite
Applications for receiving Facebook updates and notifications without having to keep the site open in a browser keep coming out. Here are eight ...

Updating how Cost per Click is Measured on Facebook
To help advertisers better understand how their ads perform, we're updating the definition of cost per click on Facebook. Learn what the change ...

Updating Your App for iOS 9: What You Need to Know
Updating Your App for iOS 9: What You Need to Know

Facebook for iPhone 3.0 to Include Page Updating
... who want to more easily update their Facebook Pages on the go: Facebook for iPhone 3.0 , which should be released soon, will include Page updating, ...

Updating trends on mobile
Trends are a great way to find out what people are talking about on Twitter at a given moment and at a single glance. Starting today, we’re making ...

Delhi Metro Fare Calculator and Auto-Updating Map on the App Store on iTunes
Get Delhi Metro Fare Calculator and Auto-Updating Map on the App Store. See screenshots and ratings, and read customer reviews.


Updating Emma: Jane Austen's classic joins list of literary reworks
Jane Austen published six novels. Just six. She died before she completed the seventh.

Tips For Updating Your Appearance
Like Joe Hockey, all men can pull off a radical mid-life makover by following some simple guidelines.

Resources last updated: 12/27/2015 11:27:36 PM