Click here to Skip to main content
15,882,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
greetings for the day,
hey guys i am using dropdownlist with switch statement but mine code is not working well the cursor is not stoping at any case and goin to stop only at default either i am selecting inkjet or the other guys kindly help me its urgent i am sending mine code i will highly thankful to you.


C#
string entity;
        entity = DropDownList1.SelectedItem.Text;
        Label10.Text = entity;
        switch (entity)
        {
            case 'inkjet':
                int p = int.Parse( TextBox4.Text);
                int g = p * 45;
                Label12.Text = g.ToString();
                break;

            case "lazerprinter":
                int f = int.Parse(TextBox4.Text);
                int y = f * 66;
                Label12.Text = y.ToString();
                break;

            default :
                Label12.Text = "kindly select a printer type";
                 break;
        }
Posted
Comments
Shemeemsha (ഷെമീംഷ) 31-Oct-14 7:42am    
Debug it.. Using debugger check the value of entity.
case 'inkjet': is wrong, case "inkject" is the correct format..
Member 10874581 31-Oct-14 7:48am    
checked value is coming
Shemeemsha (ഷെമീംഷ) 31-Oct-14 7:59am    
Oh..OK..
entity = DropDownList1.SelectedItem.Text;
After this line write a simple "IF" block to check that value is in correct format or not. Or write a code like

var abcd = entity=="inkjet"?true:false;

And check the value of abcd
Member 10874581 31-Oct-14 8:04am    
thanks
puneeth dh 31-Oct-14 8:07am    
After reading selected item. use trim function and check the two strings are same or use StringComparison.OrdinalIgnoreCase .

1 solution

C#
entity = DropDownList1.SelectedItem.Text.trim();

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