I'm trying to set a value for TextLabel
when the the LinkButton
MessageName is clicked. However I'm not having any luck.
I tried using DataList.SelectedItem.FindControl("blah")
as shown here but SelectedItem
keeps returning null
.
I also tried something like this stackoverflow question but it's not working as well.
<asp:DataList
ID="dlMessages"
runat="server"
DataSourceID="dsMessages">
<EditItemStyle Font-Names="Courier New" />
<ItemStyle BorderStyle="NotSet" />
<ItemTemplate>
<div>
<table>
<tr>
<td><asp:LinkButton ID="MessageName" Text="Some stuff" runat="server" /></td>
<td>...</td>
</tr>
</table>
<asp:Label ID="TextLabel" runat="server />
</div>
</ItemTemplate>
protected void DataList_OnItemCommand(object sender, EventArgs e)
{
if (dlMessages.SelectedItem == null)
return;
DagSelect.Text = ((LinkButton) dlMessages.SelectedItem.FindControl("MessageName")).Text;
Label l = (Label) dlMessages.SelectedItem.FindControl("TextLabel");
l.Text = DagSelect.Text;
}
Does anyone know a good way to do this? Basically, I only want the text to be displayed when the item is selected. When it's not, the string should remain empty/invisible.