Hi,
I have a datalist control which uses repeatcolunm. I want to make Datalist items clickable and get the clicked item value into a textbox outside the datalist. I did this and it works only when I set "RepeatLayout="flow"" which cancels the "repeatcolunm" which is very necessary in my case. Below is code:
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource2" RepeatDirection="Horizontal" ShowFooter="False" ShowHeader="False" RepeatColumns="21" OnItemDataBound="DataList1_ItemDataBound" OnItemCommand="DataList1_ItemCommand" >
<ItemStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False"/>
<ItemTemplate>
<asp:LinkButton id="SelectButton" Text="select" CommandName="Select" runat="server" style="display:none"/>
<a href="#"> <asp:Label ID="SpotNameLabel" runat="server" Text='<%# Eval("SpotName") %>' CssClass=" badge" /></a>
<br />
<br />
</ItemTemplate>
<SeparatorStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Size="Large" Font-Strikeout="False" Font-Underline="False" />
</asp:DataList>
C#:
protected void DataList1_ItemDataBound(object sender,
DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
//Add eventhandlers for highlighting
//a DataListItem when the mouse hovers over it.
e.Item.Attributes.Add("onmouseover",
"this.oldClass = this.selectedSeat;" +
" this.selectingSeat = 'EntryLineHover'");
e.Item.Attributes.Add("onmouseout",
"this.selectingSeat = this.oldClass;");
//Add eventhandler for simulating
//a click on the 'SelectButton'
e.Item.Attributes.Add("onclick",
this.Page.ClientScript.GetPostBackEventReference(
e.Item.Controls[1], string.Empty));
}
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
txtSpotNo.Text =((Label)e.Item.FindControl("SpotNameLabel")).Text;
}