Showing posts with label ItemCommand Event. Show all posts
Showing posts with label ItemCommand Event. Show all posts

Thursday, January 12, 2012

Finding DataListItem in ItemCommand Event of DataList

Dear Friends,

In this post I am going to show how to get the DataLIstItem in ItemCommand Event of a DataList

Here is code for this purpose

protected void dlTest_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "FindPersonDetail")
{
DataListItem dlItem = (DataListItem)((Control)e.CommandSource).Parent;
string Empname = ((Label)(item.Controls[1].FindControl("lblEmpName"))).Text;
}

In this code, if the command name is FindPersonDetail then I find DataLIstItem of Datalist of the selected Item using Bubble Event. then I find My Label using that DatalistItem.
You can bypass if condition if you not require that.

Hope this code help you...