How To Display A Confirmation Dialog And Cancel The Postback When Using A Telerik RadButton



TODO:

You are using a Telerik RadButton, and you want to display a Confirm Dialog, and capture the user pressing cancel, thus canceling the Postback.

 

SOLUTION:

    <!-- Define button, and put method to call in the OnClientClicking event -->

    <telerik:RadButtonID="btnDelete"runat="server"Text="Delete Customer"OnClick="btnDelete_Click"

        OnClientClicking="ConfirmDelete">

    </telerik:RadButton>

   

    <!-- Confirm action here.  Cancel press in this dialog will return FALSE, which in turn we will catch and set cancel = true in the args -->

    <telerik:RadCodeBlockID="RadCodeBlock1"runat="server">

        <scripttype="text/javascript">

            function ConfirmDelete(sender, args) {

                if (!confirm('Delete Customer, do you wish to proceed?')) {

                    args.set_cancel(true);

                }

            }

        </script>

 

    </telerik:RadCodeBlock>

 

NOTES:

You may not need the RadCodeBlock, I did in this case due to Application

How To Remove An Image From The Header Text Of A RadGrid Column



TODO:

Have you ever wanted to remove an image from the Header Text of a Telerik RadGrid?

 

SOLUTION:

/// <summary>
/// Add Header Image
/// </summary>
/// <param name="TargetGrid"></param>
/// <param name="HeaderText"></param>
protected void RemoveGridHeaderImage(RadGrid TargetGrid, string HeaderText)
{
     GridHeaderItem headerItem = (GridHeaderItem)TargetGrid.MasterTableView.GetItems(GridItemType.Header)[0];
     try
     {
          headerItem[HeaderText].Controls.AddAt(1, space);
          headerItem[HeaderText].Controls.AddAt(2, img);
     }
     catch
     {
     }
}

 

NOTES:

All you have to do, is call this method in the PreRender() method of your RadGrid.  You can use this in conjunction with adding an image to a RadGrid Header at this link, which will allow you to toggle the image on and off depending on the contents of the grid.

How To Add An Image To The Header Text Of a RadGrid Column



TODO:

Have you ever wanted to add an image to the Header Text of a Telerik RadGrid?

 

SOLUTION:

/// <summary>
/// Add Header Image
/// </summary>
/// <param name="TargetGrid"></param>
/// <param name="HeaderText"></param>
/// <param name="ImageUrl"></param>
protected void AddGridHeaderImage(RadGrid TargetGrid, string HeaderText, string ImageUrl)
{
     GridHeaderItem headerItem = (GridHeaderItem)TargetGrid.MasterTableView.GetItems(GridItemType.Header)[0];
     Image img = new Image();
     Literal space = new Literal();
     space.Text = " ";
     try
     {
          img.ImageUrl = ImageUrl;
          headerItem[HeaderText].Controls.AddAt(1, space);
          headerItem[HeaderText].Controls.AddAt(2, img);
     }
     catch
     {
     }
     finally
     {
          img.Dispose();
     }
}

 

NOTES:

All you have to do, is call this method in the PreRender() method of your RadGrid.

Possible Cause For "Sys.ArgumentException: Value must not be null for Controls and Behaviors. Parameter name: element" When Using Telerik RadGrid



TODO:

You have a Telerik RadGrid and when you click on the Add button, you get the " Sys.ArgumentException: Value must not be null for Controls and Behaviors. Parameter name: element" error.

 

SOLUTION:

In my case I had the following structure:

Panel 1

FormGroup (a control we built)

Panel 2

RadGrid 1

 

I had AjaxSettings in my code behind for "Panel 1" and "FormGroup".  Having AjaxSettings for the nested controls caused my issue.  I removed the AjaxSetting for "FormGroup" and the issue went away


NOTES:

There are no notes on this topic.

How To Dynamically Sort a List<T> During the SortCommand Of a Telerik RadGrid



TODO:

Have you ever wanted to catch the Sort Event of a Telerik RadGrid, and sort your datasource?   This comes in handy if you are using the rows in the grid as a 1 to 1 map with items in the datasource.  This saves you from needing to worry about working with the rows and columns of a grid, but instead you can work with the List of Objects, and simply ReBin().

 

SOLUTION:

protected voidrgdMyGrid_SortCommand(object source, Telerik.Web.UI.GridSortCommandEventArgs e)
{  
    //check the sort order.  if it is descending, then we need to order list that way, otherwise use default of ascending.
    Func<MyObject, string> orderByColumn =null;
    
    //Figure out which sort column
    switch (e.SortExpression)
    {
        case "FirstName":
            orderByColumn = s => s.FirstName;
            break;
        case "LastName":
            orderByColumn = s => s.LastName;
            break;
        case "Telephone":
            orderByColumn = s => s.Telephone;
            break;
    }
    
    //now check the sort order, and sort accordingly
    if (e.NewSortOrder == GridSortOrder.Descending)
    {
        myDataSource = myDataSource.OrderByDescending(orderByColumn).ToList();
    }
    else
    {
        myDataSource = myDataSource.OrderBy(orderByColumn).ToList();
    }
    rgdMyGrid.DataSource = null;
    rgdMyGrid.Rebind();
}

 

NOTES:

MyDataSource is a List<MyObject>.  I was using the datasource for the grid and had to keep them in sync, because sorting the grid did not by default sort the datasource.  You also need to sort the datasource on insert, update, and delete of an item in the RadGrid, if a sort column is selected.