Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi There Good day,

I have created a formview.It contains many fields,and data should be retrieved from the database.Now the problem is I need to dispaly data to a textbox depending on the value selected from the dropdownlist.
For example if selected value from dropdownlist is On Transaction the value of text box must be zero.If dropdownlist selected value is not on transaction then the textbox should be empty.
Can any one please provide me an example for this.

Thanks in advance.
Posted
Updated 18-Feb-11 22:34pm
v2

If its a small predefined set of data you have in the drop down, you could use a switch case statement. Switch values based on the drop down value selected.

For a larger number of items in the dropdown, you could build your own translation class (with constants) or use a database.
 
Share this answer
 
v2
Comments
Espen Harlinn 20-Feb-11 9:16am    
Good advice, a 5
Abhinav S 20-Feb-11 10:08am    
Thanks Espen.
We can't do that: your question is too vague.

"if selected value from dropdownlist is On Transaction the value of text box must be zero"

Why zero? How would we know? You might - because it is part of your business logic. But we can't.

All we can do is suggest that you handle the SelectedIndexChanged event and update your textbox appropriately.
 
Share this answer
 
Comments
Olivier Levrey 19-Feb-11 7:59am    
I agree. I don't see any difficulty there...
Espen Harlinn 20-Feb-11 9:15am    
Good reply :)
Hi Neha 427,

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    switch (comboBox1.Text)
    {
        case "Transaction":
            textBox1.Text = "0";
            break;
        case "Not Transaction":
            textBox1.Text = "";
            break;
    }
}


I hope this help,
:)
 
Share this answer
 
Comments
Olivier Levrey 19-Feb-11 8:00am    
Voted 5.
Espen Harlinn 20-Feb-11 9:17am    
Nice and simple, my 5
Michael Waguih 22-Feb-11 3:37am    
Thanks for voting :)
You may build a Custom ComboBox control which contains some additional data. for example something like below.

XML
<asp:DropDownList ID="DropDownList1" runat="server"
    onselectedindexchanged="DropDownList1_SelectedIndexChanged" >
<asp:ListItem valueForTextBox="0">Transaction</asp:ListItem>
<asp:ListItem valueForTextBox="100">Non Transaction</asp:ListItem>
</asp:DropDownList>


and in code-behind

C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
   {
      Textbox1.Text = DropDownList1.SelectedItem.valueForTextBox;

   }




following link can help
Custom ComboBox server control for ASP.NET[^]
 
Share this answer
 
C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
   {
      Textbox1.Text = DropDownList1.SelectedIndex;
   }


You have to input the Index as you want to your textbor corresponding your Dropdownlist..
 
Share this answer
 

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