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…

Wednesday, June 1, 2011

Convert DateTime to Indian Standard Time format in SQL Server

DATEADD() function would be used to convert UTC to IST in SQL Server.

Below is the sample code for that.

DECLARE @UTCTime As DATETIME;
SET @UTCTime = GETUTCDATE();
SELECT DATEADD(MI, 330, @UTCTime) AS IST

Happy Coding…