Listbox - selected item to call the class method directly using reflection
- by Karan
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.