Wednesday, September 3, 2014

Hello folks!

I am sharing two pieces of code that i have recently used while using DevExpress GridView control for Microsoft Visual Studio. Let me appreciate DevExpress in general for making developers life easier by providing very powerful controls for Visual Studio.

Let me quickly come back to the scenario

We have a Gridview control and we need to perform some operation in the code behind and once we are done with code behind stuff then call some Javascript thing.

To carryout this, do the following steps:-

Step 1: Create a custom button under ASPxGridView Command column

Step 2: Generate an event on custom button call back as follows:-

//Code behind on custom button call back
protected void grd_Memos_CustomButtonCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomButtonCallbackEventArgs e)
 {
DevExpress.Web.ASPxGridView.ASPxGridView gridView = (DevExpress.Web.ASPxGridView.ASPxGridView)sender;
var Mem_Id = grd_Memos.GetRowValues(e.VisibleIndex, "MEM_ID");
gridView.JSProperties["WindowUrl"] = string.Format("ViewMemoReceipts.aspx?MEM_ID={0}",Mem_Id);
 }


Step 3: Go to ASPxGridView Tasks and choose Client-Side Events and add the code in the EventHandler body of Endcallback as follows:-
function(s, e) {
if (s.WindowUrl != null) window.open(s.WindowUrl);
}