Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3608350
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:29:25+00:00 2026-05-18T21:29:25+00:00

I have a problem scenario like this:- 1) Listbox with values like Car, Scooter

  • 0

I have a problem scenario like this:-

1) Listbox with values like Car, Scooter and Bike. A button to click.

    <div>
<asp:ListBox ID="lst" runat="server">
    <asp:ListItem Text="Bike" Value="Bike"></asp:ListItem>
    <asp:ListItem Text="Car" Value="Car"></asp:ListItem>
    <asp:ListItem Text="Scooter" Value="Scooter"></asp:ListItem>
</asp:ListBox>
    <br />
    <br />
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Invoke" />
</div>

2) Now i have three different class like below:-

 class Car
{
    static string getData()
    {
        return "I like cars";
    }
}

class Bike
{
    static string getData()
    {
        return "I like Bike";
    }
}

class Scooter
{
    static string getData()
    {
        return "I dont like scooter";
    }
}

3) Now on the button click event handler “Button1_Click”, i want to call the getData() method based on the selected value from the listbox using the REFLECTION only.

Please help me out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:29:25+00:00Added an answer on May 18, 2026 at 9:29 pm
    string data = (string)Type.GetType("MyAwesomeNamespace." + "Car").GetMethod("getData").Invoke(null, null);
    
    1. Type.GetType gets your Type. You might want to prefix this with your namespace
    2. GetMethod gets the getData method
    3. Invoke will execute the method. Since the method is static, invoking the method with null will work. If it wasn’t static, null had to be replace with your instance of that object. Also, the second null serves as the parameters, which are none in this case
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this scenario: One custom class (Customer) with some properties, like this: public
I had a problem with date manipulation.This is my scenario.I have a daily generating
My scenario is this: I have two listbox's, one that contains all my database
The scenario was something like this: I have 2 textboxes, say txtbox1 and txtbox2.
I have this problem in this scenario: 1-I made a new silverlight project with
I have a DataGrid that looks like this (slightly simplified here): <asp:DataGrid ID=grdQuotas runat=server
hi I have a scenario like this I made a chat program where a
The scenario is like this. I have a rich:tabPanel with about 5 tabs. On
I am in a strange problem. I have an asp.net mvc web page. Scenario
I have a chained XSLT 2.0 transformation scenario (using saxon), like this: - I1.xml

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.