Wednesday, 16 January 2013 13:15

how to use datalist commands

Written by 
Rate this item
(0 votes)

if you placed datalist command buttons as -

<asp:DataList ID="DataList1" DataKeyField="CommentId" runat="server"
OnItemCommand="DataList1_ItemCommand">
<ItemTemplate>
<asp:LinkButton ID="Edit" Text="Select" CommandName="Edit" runat="server" />
<asp:LinkButton ID="delete" Text="Approve" CommandName="Delete" runat="server" />
.......

you can easily implement those commands by the code
behind method shown here -

protected void DataList1_ItemCommand(object source,DataListCommandEventArgs e)
{
// it will find the datakey
int datakey= Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex].ToString());

if (e.CommandName == "Approve")
{
Panel user = (Panel)e.Item.FindControl("UserCommentPanel2");
//do more
}
}

you can use as many command buttons as you want by giving a unique
command name.in this example i used two command name Select and Approve.

Read 2732 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.