Listbox - selected item to call the class method directly using reflection

Posted by Karan on Stack Overflow See other posts from Stack Overflow or by Karan
Published on 2010-12-29T11:50:46Z Indexed on 2010/12/29 11:54 UTC
Read the original article Hit count: 148

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET