Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two text boxes and one drop down list.

In drop down lists data's are
iphone4-12000
iphone4s-12500

like this....

when select iphone4-12000 i want display in two textboxes..

one textbox iphon4(name)

another textbox 12000(price)

What I have tried:

<asp:DropDownList  ID="DropDownList1" runat="server">
                  <asp:ListItem Value="0">--Select--</asp:ListItem>
<asp:ListItem Value="1">Iphone4</asp:ListItem>
<asp:ListItem Value="2">Iphone4s</asp:ListItem>
<asp:ListItem Value="3">Iphone5</asp:ListItem>
<asp:ListItem Value="4">Iphone5s</asp:ListItem>
<asp:ListItem Value="5">Iphone6</asp:ListItem>
<asp:ListItem Value="6">Iphone6s</asp:ListItem>
<asp:ListItem Value="7">Iphone7</asp:ListItem>
<asp:ListItem Value="8">Iphone 7 Plus</asp:ListItem>


                </asp:DropDownList>
Posted
Updated 28-Feb-17 23:30pm
Comments
Graeme_Grant 1-Mar-17 5:19am    
What have you tried so far?
GrpSMK 1-Mar-17 5:21am    
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
textbox.Text = DropDownList1.SelectedItem.Text;

}

 
Share this answer
 
Comments
GrpSMK 1-Mar-17 5:27am    
i know how to fill in one textbox,i want to split the dropdown value and insert into two textboxes
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
           string text  = DropDownList1.SelectedItem.Text;
           string[] parts = text.Split('-');
           if (parts.Length == 2)
           {
               TextBox1.Text = parts[0];
               TextBox2.Text = parts[1];
           }

        }


Using Javascript

ASP.NET
<asp:DropDownList ID="DropDownList1" onchange="setvalues(this)" runat="server">
            <asp:ListItem Value="0">--Select--</asp:ListItem>
            <asp:ListItem Value="1">Iphone4-3333</asp:ListItem>
            <asp:ListItem Value="2">Iphone4s-43434</asp:ListItem>
            <asp:ListItem Value="3">Iphone5-454545</asp:ListItem>
            
        </asp:DropDownList>
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
        <asp:TextBox ID="txtPrice" runat="server"></asp:TextBox>

JavaScript
function setvalues(obj)
        {
            var text = obj.options[obj.selectedIndex].text;
            var parts = text.split('-');
            document.getElementById('<%= txtName.ClientID %>').value = parts[0];
            document.getElementById('<%= txtPrice.ClientID %>').value = parts[1];

        }
 
Share this answer
 
v3
Comments
Graeme_Grant 1-Mar-17 5:34am    
Is that javascript?
Karthik_Mahalingam 1-Mar-17 5:42am    
c#
Graeme_Grant 1-Mar-17 5:44am    
Was a rhetorical question... The code in the question looked like he was looking for a javascript solution ... postback is the long way round...
Karthik_Mahalingam 1-Mar-17 5:48am    
yes, but he has not tagged javascript in the question.
posted js solution too.
Graeme_Grant 1-Mar-17 6:31am    
Not tagged C# either if you want to go down that road...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900