简体   繁体   中英

how to write a switch in c#

I'm working on asp.net and c# to create 1 application in which I'm facing a problem.the problem is.

I have 3 link buttons named on a single page.

  1. category
  2. location
  3. username

That page also includes one TextBox through which I'm searching the users by category and all. I have created web services for searching the users by category,name and location.

But what I want is when I click on link button category, only category web service will be called not other 2 similarly for others.

When a user clicks on the specific button, you need to send the request to another function.

public function void catagory_click()
{
   Getservice("Cat");
}
public function void location_click()
{
   Getservice("Loc");
}
public function void username_click()
{
   Getservice("Usr");
}

function void Getservice(string _selButton)
{
    switch(_selButton)
    {
        case 'Cat': 
        // call catagory webservice
        break;
        case 'Loc': 
        // call Location webservice
        break;
        case 'Usr': 
        // call Username webservice
        break;
        default : 
        //call default service
    }
}

Reference: http://www.tutorialspoint.com/csharp/switch_statement_in_csharp.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM