I need to create a series of dynamically created buttons inside of a repeater. These buttons names are coming from a database. When a user clicks a button, some hidden text beside the name appears. And disappears when clicked again. The text will have to be either defined in the html or the code behind.
Here is some code to demonstrate what I'm thinking.
<asp:Repeater ID="Repeater1" DataSourceID="DecisionDetailsDS" runat="server" >
<ItemTemplate>
<asp:Button ID="DecisionButton" runat="server" OnClick="BTN_ShowText" BorderStyle="None"
Text='<%# Eval("Decision_Type_Dsc") %>' />
<asp:Label ID="DecisionLabel" Visible="false" runat="server" />
<p></p>
</ItemTemplate>
<AlternatingItemTemplate>
<asp:Button ID="DecisionButton" runat="server" OnClick="BTN_ShowText" BorderStyle="None"
Text='<%# Eval("Decision_Type_Dsc") %>' />
<asp:Label ID="DecisionLabel" Visible="false" runat="server" /> <p></p>
</AlternatingItemTemplate>
</asp:Repeater>
public void BTN_ShowText(Object sender, EventArgs e)
{
Label TestLabel = (Label)FindControl("DecisionLabel");
Button TestButton = (Button)FindControl("DecisionButton");
switch(TestButton.Text)
{
case "Dismissed":
TestLabel.Text = "Testing 1 2 3";
break;
case "Anything":
TestLabel.Text = "Testing 2 3 4";
break;
}
if (TestLabel.Visible == false)
{
TestLabel.Visible = true;
}
else
{
TestLabel.Visible = false;
}
}
}
I know this doesn't work. I get nulls returned. Whereas I need the id of the button and it's corresponding label. Hopefully this gives you an idea of what I'm trying to do. Any suggestions are appreciated especially if you provide my some code to work with. I thought maybe using jquery?
I am new to .net/jquery programming. Hopefully someone can help me. Thanks!