Sunday, 11 August 2013

Datalist Itemcommand event is not working

Datalist Itemcommand event is not working

I am trying to work on itemcommand event of datalist. I want to work with
the button that is bind in datalist. But when i add a breakpoint on the
itemcommand event the event doesnot run.Please tell me why it is not
working here is the datalist source and my code
<asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal"
onitemcommand="DataList1_ItemCommand1" >
<ItemTemplate>
<ul>
<li>
<a href="#"><asp:Image ID="Image1" runat="server"
ImageUrl='<%#Eval("pictureurl") %>' Width="170px" Height="104px"
/></a><br /><br />
<asp:Label ID="Label1" runat="server" Text='<%#Eval("fullname")
%>'></asp:Label><br />
<asp:ImageButton ID="ImageButton2" runat="server"
ImageUrl="~/images/Icons/accept1.png" CommandName="Accept"
/>&nbsp;<asp:ImageButton ID="ImageButton1"
runat="server" ImageUrl="~/images/Icons/decline.png"
/>&nbsp;
</li>
</ul>
</ItemTemplate>
</asp:DataList>
Code:
if (e.CommandName == "Accept")
{
string id = DataList1.DataKeys[e.Item.ItemIndex].ToString() ;
SqlCommand CmdAcceptRequest = new SqlCommand("Update
FriendRequest set requeststatus='Accept' where RequestFrom='"
+ id + "'", con);
CmdAcceptRequest.CommandType = CommandType.Text;
CmdAcceptRequest.ExecuteNonQuery();
CmdAcceptRequest.Dispose();
}
This code is not working for me there is no response from the itemcommand
event please tell me where i am going wrong

No comments:

Post a Comment