Select value from drop down then other fields shows value in textfield depends on the dropdown.

 Hi,
em new in VB.NET & develop a web based transaction which is almost 50% complete.

my problem is that i have a form of Item properties, which consist on a following fields,

1. Item
2. Unit
3. Old Price
4. New Price

 my client wants that if user select Item from the dropdown then other fields shows value automaticlly on the textfields which is depend on the item name.

for example:

if user select Colgate from the dropdown then Unit, Old Price and New Price shows in textfeilds seperately. 

 if u have any code and tutorial about the above example then kindly share with me i will be very thankful.

 
Kindly solve my problem as soon as possble.

0
asad_black
11/11/2008 7:57:17 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies
904 Views

Similar Articles

[PageSpeed] 16

Hi asad_black,

Try something like this :

 

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database2.mdf;Integrated Security=True;User Instance=True");
        SqlCommand com = new SqlCommand("select countryname from country where countryid = " + this.DropDownList1.SelectedValue, con);
        
        con.Open();
        SqlDataReader reader =  com.ExecuteReader();
        while (reader.Read())
        {
            this.TextBox1.Text = reader.GetString(0);
        }
        con.Close();
        
    }
  
    <form id="form1" runat="server">
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
            SelectCommand="SELECT * FROM [country]"></asp:SqlDataSource>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"
            DataTextField="countryname" DataValueField="countryid" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
        </asp:DropDownList>
        
    </form>

 

 



Samu Zhang
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.
0
Samu
11/13/2008 3:27:26 AM

 Here is a Sample done using FormView. Place a DropDownList which consists of all the Items. Once Item is selected, display the details in the Form Fiew.

 

<form id="form1" runat="server">
        <div>
            <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">
                <ItemTemplate>
                     <br /><br />
                    Unit:
                    <asp:Label ID="lblUnit" runat="server" Text='<%# Eval("Unit") %>' /><br /><br />
                    Old Price:
                    <asp:Label ID="lblOldPrice" runat="server" Text='<%# Eval("OldPrice") %>' /><br /><br />
                    New Price:
                    <asp:Label ID="lblNewPrice" runat="server" Text='<%# Eval("NewPrice") %>' /><br /><br />
                </ItemTemplate>
            </asp:FormView>
                    <asp:DropDownList ID="ddl" runat="server" DataTextField="Product" DataValueField="PId" AutoPostBack="True" DataSourceID="SqlDataSource2" style="position: relative" /><asp:SqlDataSource
                        ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
                        SelectCommand="SELECT * FROM [Products]"></asp:SqlDataSource>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
                SelectCommand="SELECT * FROM [Details] WHERE ([ProductId] = @ProductId)">
                <SelectParameters>
                    <asp:ControlParameter ControlID="ddl" Name="ProductId" PropertyName="SelectedValue"
                        Type="Int32" />
                </SelectParameters>
            </asp:SqlDataSource>
        </div>
    </form>

  

Code Behind:

 

public partial class Items : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ddl.DataBind();
        }
    }
}
  
Cheers,
Achutha Krishnan

~ No one can do everything, but everyone can do something ~
0
engineerachu
11/13/2008 4:54:41 AM
Reply:

Similar Artilces:

Drop down list control values OK but not showing selected value on UI
 Hi, I am having trouble with the following: ddlIndustry.Items.FindByText(oReader["industry"].ToString()).Selected = true;  I am trying to get the ddlIndustry drop down list to bind to a specific product industry got from a database like say "Agriculture". Even when i assign a hardwired and existent value like "Agriculture" as from the database,  the Selected value or text does change from initial option from the list with (this I verified in Debug mode) but when the page is generated, the Drop down list maintains value 0 and text "--select one --". Is there something i am...

when loading a previously created record on to form, some controls are missing values(controls are depended on values selected in other controls)
Hello - I have created a page for Editing records.  this page will open up a chosen record and allow user to edit the data.On the form, I have 3 drop down lists.   The second dropdown list should fill values depending on value chosen in first dropdown list.  The third dropdown list should show/fill values depending on value chosen in second dropdown list.So taking this into count, i have several records with various data.  When I open-up/load a record in Edit form, only the first dropdown list has a value selected that was the pre-existing va...

Selecting value in one field then causes value in another field to be selected.
I have a web form which contains a date field, the date is populated using a DatePicker which is Javascript based. The form also has a drop down box containing 3 values. What I want to do is when a date has been selected that this will cause the dropdown list value to change to dated which is one of its 3 values. i.e. when the date field is not blank then the value will be selected in the dropdown. What I also want to happen is when the date has been selected and the dropdown value is dated then the date field and the dropdown field will be set to read only.Anyone any ideas how to this usin...

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

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

dropdown selected value and dropdown no value saved
 is there any way the selected value is selected already when i try to edit the gridview ... and another thing... when i edit this dropdown.. no value was being saved... what is wrong or missing.. please help... i almost spend two days on this problem...i've read many post about this.. but still i didn;t get it... please help///  <asp:TemplateField HeaderText="Unit" SortExpression="UnitID">                          &...

hide only the dropdown value while selecting the another dropdown value
 hai  friend i am using two dropdown list if i select one dropdownlist the another dropdownlist value must be hidewhat can i do for this     Ramesh.Dhttp://rameshduraikannu.blogspot.com  u can do that using javascript..function Hide(){ var drop1 = document.getElementById('<%=dropdownlist1.ClientID%>')  var drop2 = document.getElementById('<%=dropdownlist2.ClientID%>')  if(...

Cascading Dropdown - Initially selected value
Hi there, I am having an issue with a pretty basic problem. I have managed to get the cascading drop down lists working ok with information coming from a database. On the initial page, I need to have a value in the drop down list already selected, i.e. the current year in one drop down and current month in the next. The information from both of these is sent to a query to output a datatable. Can anyone help with this? I'm not sure I understand the scenario, but I think the new CascadingDropDownNameValue(..., defaultValue) constructor may be just what you're looking for. (First available ...

DROP DOWN LIST : SHOW SOME DEFAULT SELECTED VALUE USING CASCADING DROPDOWN
Hi , I am using Cascading DropDown List in my aplication and i want to show some default selected value in the first drop down and according in the child drop down. I ahve created webservice to populate my Drop Downs. Please tell me if there is any way i can do that in AJAX..  Just use the Cascading DropDown Extender property "SelectedValue" to set your default value. Example (C#):CascadingDropDownExtender1.SelectedValue = "My Default";   I tried doing the same but this does not work. The reason being so defaultvalue bool is always false in in Cascadi...

problem in selecting value from dropdown inside a repeater and inserting the selected value inside db
there is  checkbox and drop down inside my  item template of repeater in one page.Based on that drop down and check box selection calculation will be done in another page which will be inserted inside a db.I cannnot fetch the value from the dropp down in my save page  and as a resut data cannot be inserted inside db. plz help!!  <asp:Repeater ID="rptmenproduct" runat="server" >                      <HeaderTemplate>    <...

Dropdownlist selected value passes first value in list no matter what value is selected. why ?
 HI . I have a dropdownlist. Databinds ok but when I must pass a value as a Selected value it always passes the first value in the list even if I select another value. I tried to set the ddl to enableviewstate false but it doesn't change anything. Any ideas ? Code below, thanksLoading the ddl:       productCategories = CatalogAdmin.Admin_Product_Categories_NotIn(productId);        for (int i = 0; i < productCategories.Rows.Count; i++)        {       &...

Cascading Dropdown Selected values and Default values
I am loading the cascading dropdown control with data from my database implementing web service methods written in VB, and cascading dropdown control runs fine. Now as in any classic application I would like giving default values to  3 dropdown lists concerned with cascading and also getting back selected entries to call my database to retrieve records with values read as criteria. First I tried to postback with a button control after selecting entries in cascading dropdown control, but the resulting selected values are empty. Can anyone help. Hi, As you click the Button...

adding values to the selected value in Dropdown list
 Hi,   I have dropdown box in my page which have some value inherted from the another list box in my page..Now in my second page , i have dropdown box with values and text value and list box... I'll be selecting the one value from the dropdown then i enter the value in text box and click on add button which will add the value in the list box like this i can able to add many value...now if i click on save button for the selected dropdpown item the added values in the listbox should be saved ...like this i add many values for many dropdown item and saved respectivelynow if c...

Control.Value and Control.SelectedItem.Value
Can someone explain to me the difference between say, Dropdownlist.SelectedItem.Value and Dropdownlist.SelectedValue?? Just curious, Thanks!Tim These are going to return the same thing. dropdownlist.selectedvalue is a shortcut to get the currently selected value in the dropdown. If that is all you want then you can just use that. If you want to access the currently selected item you can use dropdownlist.selecteditem and that return the item and you can then access any of the item's properties, including in this case the value property. If this post answered your question please r...

Web resources about - Select value from drop down then other fields shows value in textfield depends on the dropdown. - asp.net.presentation-controls

smartNote for iPad on the iTunes App Store
Read reviews, get customer ratings, see screenshots, and learn more about smartNote on the App Store. Download smartNote and enjoy it on your ...

ActionScript - Wikipedia, the free encyclopedia
ActionScript is an object-oriented language originally developed by Macromedia Inc. (now owned by Adobe Systems ). It is a dialect of ECMAScript ...

Contact Us
Thank you for choosing to contact Adelaide ACA. Please use the form below and one of our expert automotive dealers will be in touch.

Contact Us
Thank you for choosing to contact Infinite Eye. Please use the form below and one of our website experts will be in touch.

Fields Of Meaning/Becoming
When we discuss the engaging aspects of Recombinant Poetic works, we need to seek a conceptthat can help us understand the operation of how meaning ...

Contact the Mackay Branch
Cherish Life Queensland all life is special cherish it - not abortion. Formerly Right to Life Queensland. Cherish Life Queensland is a non-denominational, ...

Fillip / Advertising Information
Fillip, a contemporary art magazine from Vancouver, Canada

Form builder example - 2h.com
Skip to main content 2h.com All the tests you need Main menu Home IQ tests Personality tests EQ tests Articles You are here Home Navigation Form ...

Send Email From Spotlight With SpotMail Jailbreak Tweak
... Search page. Once download and installed, users can email from Spotlight simply by entering an email address in the Spotlight Search textfield, ...

OS X Lion: About FileVault 2
OS X Lion provides a new version of FileVault: FileVault 2 uses full disk, XTS-AES 128 encryption to help keep your data secure. With FileVault ...

Resources last updated: 1/4/2016 5:21:06 AM