Tuesday, June 7, 2011

Simulating ListView’s ItemCommand Event

Data controls in asp.net like GridView, DataList, Repeater, ListView,… are having an event called ItemCommand.

This event will raise whenever any button, linkbutton,… are clicked.

But my requirement is to call the ItemCommand event whenever the ListView.Databind() is done.

Below is the procedure I followed for that.

System.Web.UI.WebControls.LinkButton lnkbtn = (System.Web.UI.WebControls.LinkButton)lvMyAlbums.Items[0].FindControl("lnkAlbum");

            ListViewCommandEventArgs ev = new ListViewCommandEventArgs(lvMyAlbums.Items[0], lnkbtn, new CommandEventArgs(lnkbtn.CommandName, lnkbtn.CommandArgument));

            // Call ItemCommand handler

            lvMyAlbums_OnItemCommand(lvMyAlbums, ev);

 

Happy coding…

No comments:

Post a Comment