Hi,
If you have set OnItemCommand event of datalist, then why you are firing alone button click event, which is inside datalist??
Add commandname,commandargument to button and handle button click event in OnItemCommand of datalist.
<asp:datalist id="Datalist1" runat="server" datakeyfield="item_code" repeatdirection="Horizontal" repeatlayout="Table" onitemcommand="dl_item_command" xmlns:asp="#unknown">
<headertemplate>
</headertemplate>
<itemtemplate>
.....
<asp:button id="Button18" runat="server" forecolor="White" commandname="myevent">
BackColor="Teal" Font-Size="small" style="z-index: 1;font-family:Sans-Serif;
height:22px; font-weight:900;" Text="Add to cart" />
</asp:button></itemtemplate>
</asp:datalist>
protected void dl_item_command(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "myevent")
{
int index = e.Item.ItemIndex;
Label lbl = (Label)Datalist1.Items[index].FindControl("Label1");
Label4.Text = lbl.Text;
}
}
Hope it helps you.
Thanks.